lbottoni
1 week ago
149
15
Laravel

Policy never called

Posted 1 week ago by lbottoni

Hi all, i a new in laravel and i want try use the Model policy

i have create Model, ModelPolicy and Route resource. after i have registred the join class=>policy in in AuthServiceProvider.

class AuthServiceProvider extends ServiceProvider
{
    /**
     * The policy mappings for the application.
     *
     * @var array
     */
    protected $policies = [
        // 'App\Model' => 'App\Policies\ModelPolicy',
        Federation::class => FederationPolicy::class
    ];

in FederationPolicy.php

class FederationPolicy
{
    use HandlesAuthorization;
    public function delete(User $user, Federation $federation)
    {
        //i return false only for test, here i have a stop with xdebug
        return false;
        //
    }

in FederationController .php

class FederationController extends Controller
    {
    use AuthenticatesUsers;

    //  protected $redirectTo = '/public/login';
    public function __construct()
        {
            //$this->authorizeResource(Federation::class,"delete");//not work
            //$this->authorizeResource(Federation::class,"destroy");//not work
            //$this->authorizeResource(Federation::class);//not work

        }
    public function destroy(Federation $federation, Request $request)
        {
            $federation->delete()

why the delete() method never pass inside delete method of FederationPolicy ?where is my error?

the route is controlled by Route::resource('/dashboard/crud/federations', 'Admin\FederationController');

Please sign in or create an account to participate in this conversation.