This commit is contained in:
2024-09-24 17:22:09 +03:00
parent cb2c719b1b
commit 349c2992dc
13 changed files with 314 additions and 52 deletions

View File

@ -7,10 +7,13 @@ use Illuminate\Database\Eloquent\Model;
* @property string $username
* @property string $email
* @property string $password_hash
* @method static where(int[] $array)
* @method static find($id)
*/
class User extends Model {
const DEFAULT_USER_ROLE = 1;
const ADMIN_USER_ROLE = 9;
protected $table = 'user';
protected $fillable = ['username', 'email', 'password_hash', 'role'];
protected array $dates = ['deleted at'];

View File

@ -33,6 +33,11 @@ class UserService
return false;
}
public function getByField(string $field, string $value)
{
return User::where($field, $value)->first();
}
public static function createUsernameArr(): array
{
foreach (User::all()->toArray() as $user) {
@ -45,4 +50,26 @@ class UserService
return [];
}
public static function getAuthUser()
{
if (isset($_COOKIE['user_id'])){
$user = User::where("id", $_COOKIE['user_id'])->first();
if ($user){
return $user;
}
}
return false;
}
public static function getAuthUsername(): string
{
$user = self::getAuthUser();
if ($user){
return $user->username;
}
return '';
}
}