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.
Remember that routes declared in api.php
will automatically prepend the /api
prefix, e.g.:
Route::get('/hello', ...)
axios.get('/api/hello')
Your API routes are within the api
middleware which requires authentication of type API. If you check out the API Authentication documentation you need to have API tokens set up and passed in with your request.
You either need to pass the token in with your request, remove the api
middleware and have your API routes be unauthenticated, or move the routes that you need to access via browser out of the api
middleware and into the web
middleware and routes file.
Just add public in url before api.
Like
/127.0.0.1:8000/public/api/dashboard/departments
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With