Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5.3 RESTFul API without authentication

I want to create an API with Laravel 5.3 but i don't need any kind of authentication. Is it possible to get rid of it? I don't want any token or any kind of authentication.

like image 889
csharper Avatar asked Dec 07 '22 20:12

csharper


1 Answers

Yes, it's possible normally in your

route/api.php

you'd have something like

Route::middleware('auth:api')->get('/user', function (Request $request) {
   return $request->user();
});

you just need to remove the part of the middleware that's referencing auth. So the above would look like:

Route::middleware('api')->get('/user', function (Request $request) {
  return $request->user();
  //middleware('api') URI prefix. which would become '/api/user'
});

or

Route::apiResource('user', 'UserController');
//same as above but includes crud methods excluding 'create and edit'
like image 155
sgtcadet Avatar answered Dec 26 '22 09:12

sgtcadet