Skip to content

Instantly share code, notes, and snippets.

@lucasemanuel
Created June 20, 2018 14:19
Show Gist options
  • Save lucasemanuel/57ad5a20252ca5e045fe2312d6476f11 to your computer and use it in GitHub Desktop.
Save lucasemanuel/57ad5a20252ca5e045fe2312d6476f11 to your computer and use it in GitHub Desktop.
api.php 20.06
<?php
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::post('/login', function(Request $request){
// if(Auth::attempt(['email' => $request->email,
// 'password' => $request->password])){
if(Auth::attempt($request->only('email', 'password'))){
$user = Auth::user();
$token = $user->createToken('APIToken')->accessToken;
return response()->json([
'token' => $token,
'usuario' => $user,
]);
} else {
return response()->json([
'msg' => 'Não Autorizado',
], 401);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment