What Am I trying?
I already have a website and I am trying Token based authentication for an API in same code and below is the start for sample auth
In your route.php set below code
Route::group(['prefix' => API_PREFIX,'middleware' => 'auth.api'], function()
{
// Your Route
}
In your kernal.php set below middleware, it is good to use a diffrent middleware for api.
'auth.api' => \App\Http\Middleware\ApiAuthenticate::class,
Add new middleware ApiAuthenticate.php
class ApiAuthenticate
{
public function handle($request, Closure $next, $guard = 'api')
{
if (\Auth::guard($guard)->guest()) {
return response("Invalid user");
}
else {
return $next($request);
}
return $next($request);
}
}
Check your get and post methods too