Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TrederusMaximus's avatar

Problem with CSRF - VerifyCsrfToken.php line 67

Hello,

I am trying to submit a simple form :

<div class="row">
    <form name="article" method="POST" action= "/ASweb/public/articles/{{$article->id}}">
        {{--@Todo: FIND OUT WHY IS THIS NEEDED?!!--}}
        {{ csrf_field() }}
        {{ method_field('PATCH') }}
        

        <div class="col-md-4">
            <textarea name="description" class="form-control">{{$article->description}}</textarea>
        </div>
        <div class="col-md-8">
            <button type="submit" class="btn btn-primary">Save</button>
        </div>

    </form>
</div>

But I am always getting the following error message:

TokenMismatchException in VerifyCsrfToken.php line 67:

As you can see I have already included the {{ csrf_field() }}. I did this as I read that it will fix this issue and the correct token will be matched. But the problem persists. I am trying to do a post that I convert to a patch as suggested in the "Laravel from scratch" lectures and then I simply want my controller to update the fields and return to the page. Nothing special.

Any hints are appreciated! THANKS! :-)

0 likes
9 replies
alenn's avatar

Try to change {{ csrf_field() }} to this {!! csrf_field() !}}

TrederusMaximus's avatar

I've tried that but that just seems to break my code. What was the idea behind that suggestion?

TrederusMaximus's avatar

The thing is that if I look into the source on my page the token seems to be replaced in the correct way. Once I submit the form I get the mismatch exception. I now wonder what it the token compared to? Do I have any way to dump both values and see where the mismatch is? I've just started with Laravel and still do not know much about CSRF.

tomopongrac's avatar

How you route looks?

And how you session is configured

TrederusMaximus's avatar

My routes look like this:

Route::get('articles/{article}/edit', 'ArticlesController@edit');
Route::patch('articles/{article}', 'ArticlesController@update');

In my session.php is says:

'driver' => env('SESSION_DRIVER', 'file'),

Is that info sufficient?

TrederusMaximus's avatar

The folder storage/framework/sessions is writeable. As far as I understood I did things as they're supposed to be. Have the csrf_field() inside my form tags and sessions can be written... Problem persists.

TrederusMaximus's avatar

I have now also compared the value of the token in the session file and the one which gets taken into the form after I add csrf_field() and they match!! I really do not know what the problem is.

Does anyone know where exactly those 2 values are being compared within the code such that I can track that down?

TrederusMaximus's avatar
Level 4

I have solved the issue. I was having a wrong path in the link and hence the mismatch exception!

Please or to participate in this conversation.