DevGe
DevGe

Reputation: 1449

Creating Rest API Laravel (Showing 404)

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'));


}

My Route List: Router

Upvotes: 1

Views: 966

Answers (1)

Paras Raiyani
Paras Raiyani

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

Related Questions