Reputation: 1449
I created a Laravel Api-rest, but when i'm accessing the api endpoint it's responding me 404 not found. I added the endpoint in api.php
The url that I'm accessing is localhost:8000/api/my_first_api but the browser returns 404 not found.
Route::get('my_first_api',
'HomeController@my_first_api')>name('my_first_api');
HomeController.php :
public function my_first_api()
{
$home_content = DB::select('SELECT * FROM content_structure WHERE content_pages = ? ',[
'Home'
]);
return response()->json(array(['data' => $home_content]));
}
RouteServiceProvider.php :
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
Upvotes: 1
Views: 966
Reputation: 768
Please Check Your Code
Route::get('my_first_api',
'HomeController@my_first_api')->name('my_first_api');
And Just add public in url before api.
localhost:8000/public/api/my_first_api
Upvotes: 1