I have got the dreaded VerifyCsrfToken error in my Laravel 5.2 project.
Relevant codes are below:
Route which is throwing the error
Route::group(['middleware' => ['web']], function(){
Route::resource('register', 'RegisterController');
});
Error is thrown when I try to register a new user using POST request
Register Controller
public function store(Request $request)
{
return AppUser::create([
'name' => $request->input('name'),
'email' => $request->input('name'),
'contact_number' => $request->input('contact_number'),
'api_token' => str_random(60),
'password' => $request->input('password'),
]);
}
Expected Output
{
"email": "test.name",
"contact_number": "654987123",
"updated_at": "2016-10-06 06:30:26",
"created_at": "2016-10-06 06:30:26",
"id": 4
}
What makes my question different from the other VerifyCsrf mismatch questions are, I don't have a form to add a {{ csrf_token() }}
hidden field. I just sent the request using Postman (and curl) and the user needs to be registered.
When I do the following edit on app/Http/Middleware/VerifyCsrfToken.php
protected $except = [
'/*'
//
];
The error disappears and it works as it should, but I don't think is the recommended way.
Thanks