Created
January 23, 2019 07:15
-
-
Save trunghieuvn/80ae98b2799aff005b7c8bff1d20994b to your computer and use it in GitHub Desktop.
Controller.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use Illuminate\Http\Request; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Support\Facades\Auth; | |
class APIController extends Controller | |
{ | |
public function login(Request $request){ | |
if(Auth::attempt(['email' => request('username'), 'password' => request('password'), 'user_type_id' => 2])){ | |
$user = Auth::user(); | |
$success['token'] = $user->createToken('MyApp')-> accessToken; | |
return response()->json(['success' => $success], 200); | |
} | |
else{ | |
return response()->json(['error'=>'Unauthorised'], 401); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment