/
var
/
www
/
html
/
plugin-techloyce
/
app
/
Models
/
Upload File
HOME
<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Str; use Illuminate\Support\Facades\Session; class AuthToken extends Model { protected $fillable = [ 'id', 'source', 'app', 'zgid', 'identifier', 'app_refresh_token', 'app_access_token', 'app_expires_in', 'source_refresh_token', 'source_access_token', 'source_expires_in', 'webhook', 'zoho_domain', 'app_refresh_expires_in', ]; /** * @param $tokenInf * @return mixed */ public function storeToken($tokenInf){ return $this::create([ "id" => (string)Str::uuid(), "source" => Session::pull("source"), "identifier" => Session::pull("identifier"), "app" => Session::pull("app"), "app_refresh_token" => $tokenInf["data"]["app_refresh_token"], "app_access_token" => $tokenInf["data"]["app_access_token"], "app_expires_in" => $tokenInf["data"]["app_expires_in"], "source_refresh_token" => $tokenInf["data"]["source_refresh_token"], "source_access_token" => $tokenInf["data"]["source_access_token"], "source_expires_in" => $tokenInf["data"]["source_expires_in"], ]); } /** * @param $identifier * @return mixed */ public function getToken($identifier){ return AuthToken::where("identifier",$identifier)->latest()->first(); } public function updateToken($identifier,$authToken){ return $this::where("identifier",$identifier)->update([ "app_access_token"=>$authToken->access_token, "app_expires_in"=>$authToken->expires_in, ]); // "source_access_token"=>isset($authToken->source_access_token)?$authToken->source_access_token:'', // "source_expires_in"=>isset($authToken->source_expires_in)?$authToken->source_expires_in:'', } public static function checkToken($source,$app){ return self::where([ "source"=>$source, "app"=>$app, ])->first(); } }