Support the ongoing development of Laravel.io →
Database Eloquent Forms
Last updated 1 year ago.
0

Oh that one is now working when I used this :

*    public function makeAdmin($userId){
    	$user = User::where('id',$userId)->first();*
			
			
			
    	$old_role = $user->role;
    	$name = $user->name;
    	
    	$user->update([
    		'role'=>'admin'
    	]);
    	session()->flash("success","Now {$name} role {$old_role} is updated to {$user['role']}");
    	return redirect(route('users.index'));

    }

But I am still confused why the route binding User $user not worked ?

0

Do you have use App\User; in the top of the file?

0

@ Jason Weiss , Yes I used that . Otherwise it would give me a error . But it don't give me any error . it works good but the data is not updating

0

The route parameter and the controller method parameter should match.

Change userId to user in the following route:

Route::post('users/{**userId**}/make-admin','UsersController@makeAdmin')->name('users.make-admin');

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Nymur Rahman nymur Joined 14 Nov 2018

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.