coder222

Member Since 1 Year Ago

Experience Points
860
Total
Experience

4,140 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
2
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 1
860 XP
Jan
13
1 week ago
Activity icon

Replied to Can I Create Separate User And Admin Login In Laravel ?

As ankush981 guidance, you can use different guards for separating the user group as your requirement. If you use this approach then you should separate the auth controllers for admin and common users, so you can check using Auth::guard('admin')->attempt() as an example.

Activity icon

Replied to Laravel Breeze And Two Factor Authentication

The "LoginController" in Breeze is AuthenticatedSessionController, where you can find this method :

    public function store(LoginRequest $request)
    {
        $request->authenticate();

        $request->session()->regenerate();

        return redirect(RouteServiceProvider::HOME);
    }

So, I think you can put the two-factor auth code either in this store method or in the LoginRequest class.

Jan
10
1 week ago
Activity icon

Started a new Conversation Spatie\MediaLibrary\MediaCollections\Exceptions\FileDoesNotExist

I'm using Spatie media library, when I run the code below I got an error Spatie\MediaLibrary\MediaCollections\Exceptions\FileDoesNotExist

$item->addMediaFromDisk($media->getPath())
                    ->toMediaCollection('images');

The error shown is from this line (vendor\spatie\laravel-medialibrary\src\MediaCollections\FileAdder.php) :

    public function toMediaCollectionFromRemote(string $collectionName = 'default', string $diskName = ''): Media
    {
        $storage = Storage::disk($this->file->getDisk());

        if (! $storage->exists($this->pathToFile)) {     ------------> the error points to this line
            throw FileDoesNotExist::create($this->pathToFile);
        }

I dump $this->pathToFile and check the path and the file, it exists.

So, I continue to trace what is inside the exists method ($storage->exists()), and found out that $storage is an instance of Filesystem. I found a Laravel Filesystem class (vendor\laravel\framework\src\Illuminate\Filesystem\Filesystem.php), the exists method is :

  public function exists($path)
    {
        return file_exists($path);
    }

Since the path is correct and the file exists, I even test manually if file_exists(path) returns correctly and it does return true. So I guess this is not the Filesystem that is being used by the package, ~~then I found vendor\spatie\laravel-medialibrary\src\MediaCollections\Filesystem.php, I see this is the filesystem that is being used in the package service provider, but unfortunately there is no exists method!~~

UPDATE: Found out that the Filesystem class being used is vendor\laravel\framework\src\Illuminate\Filesystem\FilesystemAdapter.php which contains:

public function exists($path)
    {
        return $this->driver->has($path);
    }
Jan
02
3 weeks ago
Activity icon

Replied to Query Builder Table Alias

Ha...got it working by using DB::raw and adding backticks:

DB::raw('select id from `dbname`.`othertable` where mytbl.aaa = bbb)

not sure why I just got this idea after posting here, not one hour before...

at least I can continue...

Thanks everyone!

Activity icon

Replied to Query Builder Table Alias

because that column belongs to the first table, without alias still got the same error (Unknown column) which is correct since the second table doesn't have that column.

Anyway, I want to use DB::raw for the second sql, but the problem is I need to specify the database name of the table in the real case like this:

DB::table('dbname.othertable')->select('id')

change this to

DB::raw('select id from dbname.othertable')

doesn't work ...

Activity icon

Replied to Query Builder Table Alias

What error message are you getting without toSql?

Column not found: 1054 Unknown column 'mytbl.aaa' in 'where clause'

Activity icon

Replied to Query Builder Table Alias

tried to change it to value('id') but still got the same error, it seems not recognizing the alias from mytable since it's outside of the second DB::table... I guess.

Activity icon

Started a new Conversation Query Builder Table Alias

I want to run this SQL (simplified than the real case):

UPDATE mytable mytbl
SET col = (SELECT id FROM othertable WHERE  mytbl.aaa = bbb)

tried this using query builder

DB::table('mytable', 'mytbl')
->update([  'col' => DB::table('othertable')->select('id')->whereRaw('mytbl.aaa = bbb')->first()  ])

got QueryException: Column not found: 1054 Unknown column 'mytbl.aaa' in 'where clause'... (I have checked there is aaa column in mytable)

Any idea how to fix it?

Anyway, how to get the sql from query builder update? tried to add ->toSql() but got error Call to a member function toSql() on int.

Dec
01
1 month ago
Activity icon

Replied to Show A Page When Exception In The Middleware Occurs

Ohh okay, that's all I need. Thank you!

Activity icon

Started a new Conversation Show A Page When Exception In The Middleware Occurs

I'm using a package wherein the package there is a middleware like this:

  public function handle($request, Closure $next)
  {
	try {
		// calling a process
	} catch(SpecificException $e) {
	        
		if (! is_null(static::$handleException)) {
			$exceptionHandler = static::$handleException;

			return $exceptionHandler($e, $request, $next);
		}
              
		throw $e;
	}
}

It's simplified from the original but you got the idea, basically, we can set the callable static::$handleException and the middleware will somehow call it in the return statement.

I want to show a notification page to the user whenever the exception occurs, how to do that? Let's say I have a controller and action to show the page, I don't know how to redirect to my controller action from the middleware, or is there any other way?

Nov
11
2 months ago
Activity icon

Started a new Conversation Minify/Compress JS File?

I see my js file already >700KB when compiling in production mode (in dev mode 2MB). I think it's still big, I'm wondering if I'm not doing it correctly because when I see the compiled app.js, it is not somewhat obfuscated or compressed, for example I see a variable name still stay as it is.

In my webpack.mix.js:

mix.js('resources/js/app.js', 'public/js')

and I ran npm run production.

I tried to use .extract() but it's just separating the file to vendor.js, the total size is more or less the same.

Is there anything else to do?

Nov
04
2 months ago
Oct
31
2 months ago
Activity icon

Replied to Get All Rows From Many To Many Relationship

Thanks all, especially @silencebringer . I'll try that.

Activity icon

Started a new Conversation Get All Rows From Many To Many Relationship

I have a table named subscriptions that contains plan_id attribute. plan_id refers to a table named 'plans' (obviously) and plans table has many to many relationships to categories table.

So, a user can have many subscriptions, and may have many plans, and should have many categories too.

My question: How to get all categories that a user has (or is allowed to access)?

My query so far: (I hope it can be more simple)

$planIDs = $user->subscriptions->pluck('plan_id');

$plans = Plan::whereIn('id', $planIDs)->get();

$categories = $plans->categories; -> can not, because $plans is a collection

Do I have to iterate $plans? something like:

$plans->each(function($plan) { 
	... (get the plan category one by one)
})
Sep
10
4 months ago
Activity icon

Replied to How To Check If Checkbox Is Checked?

For checkbox input the important attributes are:

<input type="checkbox" name="cb_name" value="cb_val" checked="checked" />

When the form is submitted, the value of cb_name will be cb_val whatever its value if the checkbox is checked, if it is not checked then cb_val will not even be set.

Now you can figure out where to put your if(isset(...)) code, instead of in the value attribute it should be outside of it.

<input type="checkbox" name="cb_name" value="1" <?php if ($cb_name == 1) echo 'checked="checked"' ?> />

or if you're using laravel blade template:

<input type="checkbox" name="cb_name" value="1" @if($cb_name == 1) checked="checked" @endif />
Sep
09
4 months ago
Activity icon

Replied to Auth And Guest Middleware, How To Have Different Home Route?

Thanks all, I thought this was as easy as changing a property but after some thoughts I think I'll leave it redirecting to one page.

Sep
07
4 months ago
Activity icon

Replied to Auth And Guest Middleware, How To Have Different Home Route?

Thanks @jlrdw and @gregupton for your reply.

Ok, that should work when a user is logging in. What about a user who tries to visit a url which is not allowed for him. For example: a visitor who tries to enter member area url or a member tries to enter "/admin", as my understanding these should be intercepted by middleware and redirected to their "home" route, cmiiw.

Activity icon

Started a new Conversation Auth And Guest Middleware, How To Have Different Home Route?

In my app there are some user's roles, let's say visitor, member and admin. I want to have different home route for each role. AFAIK, the home route is defined in RouteServiceProvider, there is only one, maybe I can define more than one but how to make it work with auth or guest middleware?

Jul
28
5 months ago
Activity icon

Replied to Evaluate The Result Of A Promise

Oh okay, I never knew we can return a Promise.reject directly. Always learn new ones. Thanks!

Jul
27
5 months ago
Activity icon

Replied to Evaluate The Result Of A Promise

Thanks @piljac1 for your suggestion. I was thinking so, but then I found that the Promise that has been caught will not be caught anymore (sorry I can't explain it more clear). In this case the axios has the catch, so the error won't go into saveForm's catch. Unless I missed something here.

Jul
25
5 months ago
Activity icon

Replied to Evaluate The Result Of A Promise

Okay, thank you.

Activity icon

Started a new Conversation Evaluate The Result Of A Promise

Hi,

I have this code (Vue methods)

saveForm() {
    axios.post('/post', data)
	.then(response => response.data)   // completed normally
	.catch(err) { console.log(err) }  // error 
},

submitForm() {
	this.saveForm();
        if (result of saveForm) {   
		// do something if saving was successful
        } else {
                // handle error
        }
}

How can I evaluate the result of axios Promise?

Thanks!