1use App\Models\User;
2use Illuminate\Http\Request;
3use Illuminate\Support\Facades\Hash;
4use Illuminate\Validation\ValidationException;
5
6Route::post('/sanctum/token', function (Request $request) {
7 $request->validate([
8 'email' => 'required|email',
9 'password' => 'required',
10 'device_name' => 'required',
11 ]);
12
13 $user = User::where('email', $request->email)->first();
14
15 if (! $user || ! Hash::check($request->password, $user->password)) {
16 throw ValidationException::withMessages([
17 'email' => ['The provided credentials are incorrect.'],
18 ]);
19 }
20
21 return $user->createToken($request->device_name)->plainTextToken;
22});
1
2Route::post('/sanctum/token', function (Request $request) {
3 $request->validate([
4 'email' => 'required|email',
5 'password' => 'required',
6 'device_name' => 'required',
7 ]);
8
9 $user = \App\Models\User::where('email', $request->email)->first();
10
11 if (! $user || ! Hash::check($request->password, $user->password)) {
12 throw \Illuminate\Validation\ValidationException::withMessages([
13 'email' => ['The provided credentials are incorrect.'],
14 ]);
15 }
16
17 return response($user->createToken($request->device_name)->plainTextToken);
18});
19
20/*
21
22curl --request POST \
23 --url http://localhost:8000/api/sanctum/token \
24 --header 'accept: application/json' \
25 --header 'content-type: application/json' \
26 --data '{
27 "email":"saber.tabataba@gmail.com",
28 "password":"password",
29 "device_name":"flutter"
30}'
31
32*/