Laravel-adminlte: Add meta content for CSRF token

Created on 20 Nov 2016  路  5Comments  路  Source: jeroennoten/Laravel-AdminLTE

Could you please add <meta name="csrf-token" content="{{ csrf_token() }}"> to the master.blade.php?

Most helpful comment

A meta tag is only one way to achieve this. I do not want to force one way by adding this tag to the template.

You can easily add this to the template yourself by creating a new blade template with the following contents:

@extends('adminlte::page')

@section('css')
    <meta name="csrf-token" content="{{ csrf_token() }}">
@stop

Save this for example as resources/views/layouts/app.blade.php and then use @extends('layouts.app') instead of @extends('adminlte::page')

All 5 comments

What's the use of this? Laravel automatically inserts csrf token into your user's session, and you only really need them on form pages, as described in the docs too.

Using LaravelCollective Form library even does adding tokens on forms automatically.

Laravel also checks for CSRF tokens on ajax requests. And if you have no forms on the page, the only way to pass the token to the script is via meta tag.

Aah okay, didn't know that.

A meta tag is only one way to achieve this. I do not want to force one way by adding this tag to the template.

You can easily add this to the template yourself by creating a new blade template with the following contents:

@extends('adminlte::page')

@section('css')
    <meta name="csrf-token" content="{{ csrf_token() }}">
@stop

Save this for example as resources/views/layouts/app.blade.php and then use @extends('layouts.app') instead of @extends('adminlte::page')

We're using this one to be able to have multiple css sections:

@extends('adminlte::page')

@push('css')
    <meta name="csrf-token" content="{{ csrf_token() }}">
@endpush
Was this page helpful?
0 / 5 - 0 ratings

Related issues

bbdangar picture bbdangar  路  5Comments

vsilva472 picture vsilva472  路  4Comments

ahishamali10 picture ahishamali10  路  5Comments

Shidersz picture Shidersz  路  5Comments

Shidersz picture Shidersz  路  4Comments