0

Here is my CSRF as hidden

<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">

And my csrf is generated as usual

While i am passing into route for a controller

Here is my old route

Route::post('register', 'RegisterController@registeruser');

And to make it with csrf

Route::post('register', array('before' => 'csrf', function()
{
    return 'You gave a valid CSRF token!';
}));

as per the Laravel Docs

While i routing it to the controller

Route::post('register', array('before' => 'csrf', RegisterController@registeruser()
{
    return 'You gave a valid CSRF token!';
}));

I am getting the error

syntax error, unexpected '{', expecting ')'

What is the mistake i am doing and how can i fix this ?

1 Answer 1

2

Your route should be this:

Route::post('register', array('before' => 'csrf', 'uses' => 'RegisterController@registeruser');

Then you can handle it in your controller

class RegisterControllerextends Controller {

    protected function registeruser()
    {
        return 'You gave a valid CSRF token!';
    }

}
Sign up to request clarification or add additional context in comments.

3 Comments

And may i use like this ? Route::get('view',array('before' => 'csrf', 'uses' => 'ViewController@view'));
You would not use CSRF for GET routes. Only POST, PUT and DELETE
And in raw php i use http referer validation, is it equivalent to this ?if($_SERVER['HTTP_REFERER'] == '') {header("Location: logout");}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.