Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

40 lines (32 sloc) 1.05 KB
<?php
namespace App\Http\Controllers\API\Auth;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use App\Http\Controllers\Controller;
use Illuminate\Validation\ValidationException;
class LoginController extends Controller
{
/**
* See: https://github.com/laravel/airlock#authenticating-mobile-applications.
* @param Request $request
* @return mixed
* @throws ValidationException
*/
public function __invoke(Request $request)
{
$request->validate([
'email' => 'required|email',
'password' => 'required'
]);
$user = User::where('email', $request->email)->first();
if (! $user || ! Hash::check($request->password, $user->password)) {
throw ValidationException::withMessages([
'email' => ['The provided credentials are incorrect.'],
]);
}
$token = $user->createToken($request->device_name)->plainTextToken;
$data = ['token' => $token];
return response()->json($data, 200);
}
}
You can’t perform that action at this time.