Skip to content

Instantly share code, notes, and snippets.

@trunghieuvn
Created January 23, 2019 07:15
Show Gist options
  • Save trunghieuvn/80ae98b2799aff005b7c8bff1d20994b to your computer and use it in GitHub Desktop.
Save trunghieuvn/80ae98b2799aff005b7c8bff1d20994b to your computer and use it in GitHub Desktop.
Controller.php
<?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