79 lines
1.7 KiB
PHP
79 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Repositories\Core\Auth;
|
|
|
|
use App\Models\Core\Auth\RoleUser;
|
|
use App\Models\Core\Auth\User;
|
|
use App\Repositories\Core\Upload;
|
|
use App\Traits\Model\Basic;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Laratrust\Traits\LaratrustUserTrait;
|
|
|
|
class Users
|
|
{
|
|
use Basic, LaratrustUserTrait;
|
|
|
|
public static function getId()
|
|
{
|
|
$user = self::getUser();
|
|
|
|
return $user ? $user->id : false;
|
|
}
|
|
|
|
public static function getName($id = false)
|
|
{
|
|
$user = $id ? self::get($id) : self::getUser();
|
|
|
|
return $user->first_name.' '.$user->last_name;
|
|
}
|
|
|
|
public static function getUsername($id = false)
|
|
{
|
|
return $id ? self::get($id)->username : self::getUser()->username;
|
|
}
|
|
|
|
public static function getUser()
|
|
{
|
|
return Auth::user();
|
|
}
|
|
|
|
public static function isConnected()
|
|
{
|
|
return Auth::check();
|
|
}
|
|
|
|
public static function getOptions()
|
|
{
|
|
return User::orderBy('name')->pluck('name', 'id')->toArray();
|
|
}
|
|
|
|
public static function selectOptions()
|
|
{
|
|
return User::select('id', DB::raw("concat(last_name,' ',first_name) as name"));
|
|
}
|
|
|
|
public static function getByUsername($username)
|
|
{
|
|
return User::byUsername($username)->withTrashed()->first();
|
|
}
|
|
|
|
public static function toggleActive($id, $active)
|
|
{
|
|
return self::get($id)->update(['active' => $active]);
|
|
}
|
|
|
|
public static function updatePassword($id, $password)
|
|
{
|
|
$password = Hash::make($password);
|
|
|
|
return User::find($id)->update(['password' => $password]);
|
|
}
|
|
|
|
public static function getModel()
|
|
{
|
|
return User::query();
|
|
}
|
|
}
|