Level 50
How are you calling it?
Is it Laravel's CSRF protection that kicks in?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I am trying to update content using JSON and Laravel API, however, its returning 401 now. What I need is just to pull this content and update database.
api.php
Route::post('/track_delivery', 'NotificationController@TrackDelivery');
Route::options('{all}', 'NotificationController@options')->where('all', '.*');
Route::any('{all}', function(){
return abort(404);
})->where('all', '.*');
Notification Controller:
public function TrackDelivery(Request $request, Notification $notification)
{
return "Track Delivery Count";
}
public function options(Request $request, Response $response)
{
$origin = $request->header('origin') ?: $request->url();
$response->header('Access-Control-Allow-Origin', $origin);
$response->header('Access-Control-Allow-Headers', 'origin, content-type, accept, Authorizations');
$response->header('Access-Control-Allow-Methods', 'GET, HEAD, OPTIONS, POST, PATCH, DELETE');
return $response;
}
Any idea?
just figured it out. It was auth middleware that was kicked in by constructor of Notification controller. Updated constructor code as follows:
$this->middleware('auth', ['except' => ['TrackClose', 'TrackClick', 'TrackDelivery', 'updateSent']]);
Please or to participate in this conversation.