ERP-API/app/Repositories/Auth/AuthRepository.php

35 lines
777 B
PHP

<?php
namespace App\Repositories\Auth;
use App\Models\User;
use Hash;
class AuthRepository
{
public function login($params){
$device = @$params["device"] ?? "default" ;
$user = User::where("email",$params["email"])->first();
if (!$user){
throw ValidationException::withMessages([
"email" => "Email is not exists!"
]);
}
if (!Hash::check($params["password"],$user->password)){
throw ValidationException::withMessages([
"password" => "Password is wrong!"
]);
}
$token = $user->createToken($device);
return [$user, $token];
}
public function logout(){
auth()->user()->currentAccessToken()->delete();
}
}