%PDF- %PDF-
Direktori : /var/www/html/hrsys/api/app/Models/ |
Current File : /var/www/html/hrsys/api/app/Models/ResetPassword.php |
<?php namespace App\Models; use Illuminate\Support\Facades\DB; use Illuminate\Support\Str; use Throwable; /** * @property integer id * @property string email * @property string token */ class ResetPassword extends BaseModel { /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'email', 'token', ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'id' => 'integer', 'email' => 'string', 'token' => 'string', ]; /** * @param $email * @return string * @throws Throwable */ public static function generateToken($email) { $token = Str::random(24); try { self::query() ->create([ 'email' => $email, 'token' => $token, ]); return $token; } catch (Throwable $e) { DB::rollBack(); throw $e; } } public static function getUserByToken($token) { $item = self::query() ->where('token', $token) ->first(); return User::query() ->where('email', $item->email) ->first(); } public static function deleteByToken($token) { self::query() ->where('token', $token) ->delete(); } }