Reputation: 381
I have added the passport based API authentication in my laravel API and trying to request from Angular webapp but there is a error saying that
"NotFoundHttpException in RouteCollection.php line 161:"
calling to this route
/user/api
My route.php
<?php
header('Access-Control-Allow-Origin: *');
header( 'Access-Control-Allow-Headers: Authorization, Content-Type,Authentication,Device,UID' );
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| This file is where you may define all of the routes that are handled
| by your application. Just tell Laravel the URIs it should respond
| to using a Closure or controller method. Build something great!
|
*/
Route::group(['middleware' => 'auth:api'], function(){
Route::get('/', function () {
return view('welcome');
});
});
api.php
<?php
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::get('/user', function (Request $request) {
return $request->user();
})->middleware('auth:api');
Upvotes: 0
Views: 121
Reputation: 1035
Here's what route:list
should look with your current routes
+--------+----------+----------+------+---------+--------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+----------+------+---------+--------------+
| | GET|HEAD | / | | Closure | web,auth:api |
| | GET|HEAD | api/user | | Closure | api,auth:api |
+--------+----------+----------+------+---------+--------------+
So the correct route path is /api/user
and not /user/api
in fact every route defined in api.php
will have the /api
prefix as seen here.
Note that even if you call the correct path you might be redirected to /login
which you don't have defined so you'll get the NotFoundHttpException
error again.
Upvotes: 1