S.M_Emamian
S.M_Emamian

Reputation: 17383

define post route without csrf token

I want to call my functions from android side.

now, I want to send post values from android side.

How can I disable csrf token for some functions ?

because without it I got error message .

like this:

Route::post('mobile/android/getlastnews','NewsController@getLastNews');

Upvotes: 1

Views: 2281

Answers (2)

thefallen
thefallen

Reputation: 9749

Open app/Http/Middleware/VerifyCsrfToken.php and in the protected $except = []; array add your URL that you want to be skipped for CSRF validation.

Upvotes: 6

Leon Vismer
Leon Vismer

Reputation: 5105

For Laravel 5.2, inside app/Http/Middleware/VerifyCsrfToken.php you just need to add it to the $except array.

class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'mobile/android/getlastnews'
    ];
}

If you wanted to allow all routes for mobile/ you can do the following

protected $except = [
    'mobile/*'
];

Upvotes: 6

Related Questions