Laravel API Routes Not Found

jeesoon picture jeesoon · Mar 8, 2019 · Viewed 11.3k times · Source

Im new to API and Vue. Im working on Laravel 5.8 api.php and controllers and views and it only return 404 Not Found.

this is what ive tried

api.php

 Route::group(['middleware' => 'api'], function(){
    Route::resource('/dashboard/departments', 'DepartmentsController');
 });

Controller

class DepartmentsController extends Controller
{     
   public function index()
  {
  return 'hey';
  }
}

Route List

 GET|HEAD  | api/dashboard/departments                   | departments.index   | App\Http\Controllers\DepartmentsController@index                       | api,auth  

i tried accessing it by /127.0.0.1:8000/api/dashboard/departments and /127.0.0.1:8000/dashboard/departments but both is not working.

Answer

Eliseo picture Eliseo · Nov 1, 2019

remember than routes declared in api.php will automatically concat to /api prefix, btw:

Route::get('/hello', ...)
axios.get('/api/hello')