Stubbs
293
8
Laravel

419 Error caused by token mistmatch.

Posted 5 months ago by Stubbs

This old chestnut!

So I've got a method on my controller that has an object passed in, the object is instantiated by Laravel using it's normal mechanism.

The usual suggestion for this according to other posts seems to be to switch off middleare, but since the implicit object instantiation of now done in middlewthis doesn't work, i won't create the object and I thought csrf checking was tuned off for the testing environment?

phpconfig looks like this:

    <php>
        <env name="env" value="testing"/>
        <env name="APP_ENV" value="testing"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
        <env name="DB_CONNECTION" value="testing"/>
    </php>

The controller method:

    public function join(Club $club)
    {
        $user = Auth::user();
        $role = ClubRole::where('roles.handle', 'MEMBER')->first();
        dd($club);
        $club->setRole($role, $user);

        return redirect(route('club.show', ['club_id' => $club->id]));
    }

and the test:

    public function join(Club $club)
    {
        $user = Auth::user();
        $role = ClubRole::where('roles.handle', 'MEMBER')->first();
        dd($club);
        $club->setRole($role, $user);

        return redirect(route('club.show', ['club_id' => $club->id]));
  }

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