LaravelTest
28 строк · 561.0 Байт
1<?php
2
3namespace App\Models;
4
5use Illuminate\Database\Eloquent\Factories\HasFactory;
6use Illuminate\Database\Eloquent\Model;
7
8class Users extends Model
9{
10protected $table = 'users';
11protected $guarded = false;
12
13
14const GENDER_MALE = 1;
15const GENDER_FEMALE = 2;
16
17static function getGenders() {
18return [
19self::GENDER_MALE => 'Мужской',
20self::GENDER_FEMALE => 'Женский',
21];
22}
23//создание геттера genderTitle
24public function getGenderAttribute() {
25return self::getGenders()[$this->gender];
26}
27
28}