This is my UserPolicy:
<?php
namespace AppPolicies;
use AppModelsUser;
use IlluminateAuthAccessHandlesAuthorization;
class UserPolicy
{
use HandlesAuthorization;
public function view(User $user, User $model)
{
return $user->id === $model->id;
}
}
This is the AuthServiceProvider:
<?php
namespace AppProviders;
use AppModelsUser;
use AppPoliciesUserPolicy;
use IlluminateFoundationSupportProvidersAuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array<class-string, class-string>
*/
protected $policies = [
// 'AppModelsModel' => 'AppPoliciesModelPolicy',
User::class => UserPolicy::class
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
//
}
}
And finally the UserController
<?php
namespace AppHttpControllers;
use AppModelsUser;
use IlluminateHttpRequest;
class UserController extends Controller
{
public function show(User $user)
{
$this->authorize('view', $user);
return view('user.show', [
'user' => $user,
]);
}
}
I am trying to use $this->authorize('view', $user);
to authorize but I am getting the “Something went wrong in Ignition!” error page.
I have already spent an entire day trying to figure out what I have done wrong. Can anyone please point out what’s wrong?