Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKristofer Doman
18,307 PointsLaravel 5.4 error: Method [beforeFilter] does not exist.
$this->beforeFilter('csrf', array('on' => 'post')); // laravel 4
This isn't working in laravel 5.4 and I'm curious if anyone knows the syntax or replacement for this code. I'm not familiar with this.
1 Answer
Justin Radcliffe
18,987 PointsIn Laravel 5.0 beforeFilter() has been depricated. However, for this specific purpose of validating the CSRF token, Laravel >= 5.0 validates this automatically using middleware. The only thing you need to do is include:
{{ csrf_field() }}
in your form like so:
{!! Form::open(['route' => 'todos.store', 'method' => 'post', 'files' => true]) !!}
<div class="form-group">
{{ Form::label('title', 'List Title', ['class' => 'control-label']) }}
{{ Form::text('title', '', ['class' => 'form-control']) }}
{{ csrf_field() }}
</div>
{{ Form::submit('Submit', ['class' => 'btn btn-default']) }}
{!! Form::close() !!}