feat: inisialisasi project kit v2
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Auth;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class LoginAction
|
||||
{
|
||||
/**
|
||||
* Execute the login action.
|
||||
*
|
||||
* @param array $credentials
|
||||
* @return array
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function execute(array $credentials): array
|
||||
{
|
||||
$user = User::where('email', $credentials['email'])->first();
|
||||
|
||||
if (!$user || !Hash::check($credentials['password'], $user->password)) {
|
||||
throw ValidationException::withMessages([
|
||||
'email' => [__('auth.failed')],
|
||||
]);
|
||||
}
|
||||
|
||||
$token = $user->createToken('auth_token')->plainTextToken;
|
||||
|
||||
return [
|
||||
'user' => $user,
|
||||
'token' => $token,
|
||||
'roles' => $user->getRoleNames(),
|
||||
'permissions' => $user->getAllPermissions()->pluck('name'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user