F
F
flafy42017-01-12 13:07:11
Laravel
flafy4, 2017-01-12 13:07:11

How to remove ErrorException in VerifyCsrfToken.php error in laravel?

Good day to all. I am assigning user rights to access the site's admin panel and encountered an error ErrorException in VerifyCsrfToken.php Trying to get property of non-object. I cannot understand what is the problem.
controller:

public function __construct(Request $request)
  {
      $this->middleware(function ($request, $next) {

      	if(Gate::denies('VIEW_ADMIN')) {
      		abort(404);
      	}

      });
  }

AuthServiceProvider:
public function boot()
    {
        $this->registerPolicies();

        Gate::define('VIEW_ADMIN', function ($user) {
            return $user->canDo('VIEW_ADMIN');
        });
    }

The canDo method in the User model:
public function canDo($permission) {

        foreach($this->roles as $role) {
            foreach($role->permissions as $perm) {
                if(str_is($permission, $perm->name)) {
                    return true;
                } else {
                    return false;
                }
            }
        }

    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ramm, 2017-01-12
@rammtw

Check if there is in the form {{ csrf_field() }}
and also in the head tag

<meta name="csrf-token" content="{{ csrf_token() }}">

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question