2020-08-12 05:48:51 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use App\Contracts\Model;
|
2022-03-14 23:45:18 +08:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
2020-08-12 05:48:51 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @property string name
|
|
|
|
* @property string slug
|
|
|
|
* @property string value Only set if "squashed"
|
|
|
|
* @property bool show_on_registration
|
|
|
|
* @property bool required
|
|
|
|
* @property bool private
|
|
|
|
*/
|
|
|
|
class UserField extends Model
|
|
|
|
{
|
|
|
|
public $table = 'user_fields';
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
'name',
|
|
|
|
'description',
|
|
|
|
'show_on_registration', // Show on the registration form?
|
|
|
|
'required', // Required to be filled out in registration?
|
|
|
|
'private', // Whether this is shown on the user's public profile
|
|
|
|
'active',
|
|
|
|
];
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
'show_on_registration' => 'boolean',
|
|
|
|
'required' => 'boolean',
|
|
|
|
'private' => 'boolean',
|
|
|
|
'active' => 'boolean',
|
|
|
|
];
|
|
|
|
|
|
|
|
public static $rules = [
|
|
|
|
'name' => 'required',
|
|
|
|
'description' => 'nullable',
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the slug so we can use it in forms
|
|
|
|
*
|
2022-03-14 23:45:18 +08:00
|
|
|
* @return Attribute
|
2020-08-12 05:48:51 +08:00
|
|
|
*/
|
2022-03-14 23:45:18 +08:00
|
|
|
public function slug(): Attribute
|
2020-08-12 05:48:51 +08:00
|
|
|
{
|
2022-03-14 23:45:18 +08:00
|
|
|
return Attribute::make(
|
|
|
|
get: fn ($_, $attrs) => str_slug($attrs['name'], '_')
|
|
|
|
);
|
2020-08-12 05:48:51 +08:00
|
|
|
}
|
|
|
|
}
|