32 lines
706 B
PHP
32 lines
706 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Traits\Models;
|
|
|
|
use Illuminate\Contracts\Session\Session;
|
|
|
|
/** @mixin \Illuminate\Database\Eloquent\Model */
|
|
trait HasStar
|
|
{
|
|
public function setStar(bool $value): void
|
|
{
|
|
$this->setAttribute('star', $value);
|
|
}
|
|
|
|
public function toggleStar(): void
|
|
{
|
|
$star = boolval($this->getAttribute('star'));
|
|
$this->setAttribute('star', ! $star);
|
|
}
|
|
|
|
protected static function makeStarSense(self $model): void
|
|
{
|
|
if ($model->isDirty('star')) {
|
|
$session = resolve(Session::class);
|
|
$session->flash('info', \trans(
|
|
'crud.messages.star_saved'
|
|
));
|
|
}
|
|
}
|
|
}
|