'required|min:2|max:255|unique', ]; protected $fillable = [ 'name', 'permissions' ]; /** * Whether the model should inject it's identifier to the unique * validation rules before attempting validation. If this property * is not set in the model it will default to true. * * @var bool */ protected $injectUniqueIdentifier = true; use ValidatingTrait; use Searchable; /** * The attributes that should be included when searching the model. * * @var array */ protected $searchableAttributes = ['name', 'created_at']; /** * The relations and their attributes that should be included when searching the model. * * @var array */ protected $searchableRelations = []; /** * Establishes the groups -> users relationship * * @author A. Gianotto * @since [v1.0] * @return \Illuminate\Database\Eloquent\Relations\Relation */ public function users() { return $this->belongsToMany(\App\Models\User::class, 'users_groups'); } /** * Get the user that created the group * * @author A. Gianotto * @since [v6.3.0] * @return \Illuminate\Database\Eloquent\Relations\Relation */ public function admin() { return $this->belongsTo(\App\Models\User::class, 'created_by'); } /** * Decode JSON permissions into array * * @author A. Gianotto * @since [v1.0] * @return array */ public function decodePermissions() { return json_decode($this->permissions, true); } }