2015-12-13 12:42:28 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use App\Traits\CanFilterByUser;
|
2016-08-03 18:42:11 +08:00
|
|
|
use Illuminate\Database\Eloquent\Collection;
|
2015-12-14 08:22:39 -05:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2017-08-05 19:55:02 +01:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
2015-12-13 12:42:28 +08:00
|
|
|
|
2016-08-03 18:42:11 +08:00
|
|
|
/**
|
2018-09-03 19:41:49 +07:00
|
|
|
* @property int $user_id
|
|
|
|
* @property Collection $songs
|
|
|
|
* @property int $id
|
2018-11-04 00:25:08 +01:00
|
|
|
* @property array $rules
|
|
|
|
* @property bool $is_smart
|
|
|
|
* @property string $name
|
|
|
|
* @property user $user
|
2016-08-03 18:42:11 +08:00
|
|
|
*/
|
2015-12-13 12:42:28 +08:00
|
|
|
class Playlist extends Model
|
|
|
|
{
|
|
|
|
use CanFilterByUser;
|
|
|
|
|
|
|
|
protected $hidden = ['user_id', 'created_at', 'updated_at'];
|
|
|
|
protected $guarded = ['id'];
|
|
|
|
protected $casts = [
|
|
|
|
'user_id' => 'int',
|
2018-11-04 00:25:08 +01:00
|
|
|
'rules' => 'array',
|
2015-12-13 12:42:28 +08:00
|
|
|
];
|
2018-11-25 22:21:46 +01:00
|
|
|
protected $appends = ['is_smart'];
|
2015-12-13 12:42:28 +08:00
|
|
|
|
2018-08-24 17:27:19 +02:00
|
|
|
public function songs(): BelongsToMany
|
2015-12-13 12:42:28 +08:00
|
|
|
{
|
|
|
|
return $this->belongsToMany(Song::class);
|
|
|
|
}
|
|
|
|
|
2018-08-24 17:27:19 +02:00
|
|
|
public function user(): BelongsTo
|
2015-12-13 12:42:28 +08:00
|
|
|
{
|
|
|
|
return $this->belongsTo(User::class);
|
|
|
|
}
|
2018-11-04 00:25:08 +01:00
|
|
|
|
|
|
|
public function getIsSmartAttribute(): bool
|
|
|
|
{
|
|
|
|
return (bool) $this->rules;
|
|
|
|
}
|
2015-12-13 12:42:28 +08:00
|
|
|
}
|