2015-12-13 04:42:28 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use App\Traits\CanFilterByUser;
|
2020-09-13 22:04:07 +00:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2020-11-14 16:57:25 +00:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2015-12-14 13:22:39 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2017-08-05 18:55:02 +00:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
2021-01-05 16:52:16 +00:00
|
|
|
use Laravel\Scout\Searchable;
|
2015-12-13 04:42:28 +00:00
|
|
|
|
2016-08-03 10:42:11 +00:00
|
|
|
/**
|
2020-12-23 10:53:00 +00:00
|
|
|
* @property int $user_id
|
2018-09-03 12:41:49 +00:00
|
|
|
* @property Collection $songs
|
2020-12-23 10:53:00 +00:00
|
|
|
* @property int $id
|
|
|
|
* @property array $rules
|
|
|
|
* @property bool $is_smart
|
|
|
|
* @property string $name
|
|
|
|
* @property user $user
|
2020-09-06 21:20:42 +00:00
|
|
|
*
|
2020-09-13 22:04:07 +00:00
|
|
|
* @method static Builder orderBy(string $field, string $order = 'asc')
|
2016-08-03 10:42:11 +00:00
|
|
|
*/
|
2015-12-13 04:42:28 +00:00
|
|
|
class Playlist extends Model
|
|
|
|
{
|
2021-01-05 16:52:16 +00:00
|
|
|
use Searchable;
|
2015-12-13 04:42:28 +00:00
|
|
|
use CanFilterByUser;
|
2020-11-14 16:57:25 +00:00
|
|
|
use HasFactory;
|
2015-12-13 04:42:28 +00:00
|
|
|
|
|
|
|
protected $hidden = ['user_id', 'created_at', 'updated_at'];
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected $casts = [
|
|
|
|
'user_id' => 'int',
|
2018-11-03 23:25:08 +00:00
|
|
|
'rules' => 'array',
|
2015-12-13 04:42:28 +00:00
|
|
|
];
|
2018-11-25 21:21:46 +00:00
|
|
|
protected $appends = ['is_smart'];
|
2015-12-13 04:42:28 +00:00
|
|
|
|
2018-08-24 15:27:19 +00:00
|
|
|
public function songs(): BelongsToMany
|
2015-12-13 04:42:28 +00:00
|
|
|
{
|
|
|
|
return $this->belongsToMany(Song::class);
|
|
|
|
}
|
|
|
|
|
2018-08-24 15:27:19 +00:00
|
|
|
public function user(): BelongsTo
|
2015-12-13 04:42:28 +00:00
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
}
|
2018-11-03 23:25:08 +00:00
|
|
|
|
|
|
|
public function getIsSmartAttribute(): bool
|
|
|
|
{
|
|
|
|
return (bool) $this->rules;
|
|
|
|
}
|
2021-01-05 16:52:16 +00:00
|
|
|
|
|
|
|
/** @return array<mixed> */
|
|
|
|
public function toSearchableArray(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'id' => $this->id,
|
|
|
|
'name' => $this->name,
|
|
|
|
];
|
|
|
|
}
|
2015-12-13 04:42:28 +00:00
|
|
|
}
|