Reputation:
Hi everyone Good evening . I am practicing with laravel but i have error. I am not sure cuz i have a error 403 . I am using provider!! this is method get the id from user and use $this->authorize($user);
public function edit($id){
// buscar usuario en la base de datos y evitar
// la insercion de datos nulos
$user = User::findorFail($id);
$this->authorize($user);
return view('users.edit', compact('user'));
}
After In the class called PoliticaUsuario has method called "edit" where I wanna compare users but return false and I get error 403 or This action is unauthorized.!
class PoliticaUsuario
{
use HandlesAuthorization;
/**
* Create a new policy instance.
*
* @return void
*/
public function __construct()
{
//
}
public function edit(User $auth, User $user ){
return $auth->id === $user->id;
}
}
Obviously, this is Provider where I insert my class called PoliticaUsuario and the User Model
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
User::class => PoliticaUsuario::class,
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
//
}
}
this is the photo from database :) Pardon for my English I am still studying !!
Upvotes: 0
Views: 404
Reputation: 8957
You still need to pass the method name like this
$this->authorize('edit', $user);
Upvotes: 2