So I'm trying to store the id of my user in user_id but laravel gives the error:
{error: "Unauthenticated."}
while my user is logged in in my backoffice.
this is my routesApi.php
Auth::routes();
Route::group([
'namespace' => 'Api',
'prefix' => 'api/v1',
'middleware' => 'web'
], function () {
$options = [
'except' => [
'create',
'edit',
]
];
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
header('Access-Control-Allow-Headers: Content-Type, X-Auth-Token, Origin, Authorization, X-CSRF-TOKEN ');
Route::middleware('auth')->post('optionelections', function (Request $request) {
return $request->user();
});
});
and this is the function for my store in my controller:
public function store(Request $request)
{
$optionElection = new OptionElection();
$optionElection->user_id = Auth::id();
$optionElection->option = Auth::name();
$optionElection->votes = 0;
$optionElection->election_id = $request['election_id'];
$optionElection->accepted = 0;
if ($optionElection->save()) {
return response()
->json($optionElection);
}
}
via hxwtch