1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CosmicRadioTV\Podcast\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Collection; |
6
|
|
|
use October\Rain\Database\Model; |
7
|
|
|
use October\Rain\Database\Traits\Sluggable; |
8
|
|
|
use October\Rain\Database\Traits\Validation; |
9
|
|
|
use October\Rain\Database\Traits\Sortable; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class ReleaseType |
13
|
|
|
* |
14
|
|
|
* @package CosmicRadioTV\Podcast\Models |
15
|
|
|
* @property int $id ID |
16
|
|
|
* @property string $name Release type's name |
17
|
|
|
* @property string $slug Release type's slug |
18
|
|
|
* @property string $type Release type |
19
|
|
|
* @property string $filetype Release's filetype |
20
|
|
|
* @property int $sort_order Release type's order when sorted |
21
|
|
|
* @property-read Collection|Release[] $releases Releases that are of this type |
22
|
|
|
* @method \October\Rain\Database\Relations\HasMany releases() |
23
|
|
|
*/ |
24
|
|
|
class ReleaseType extends Model |
25
|
|
|
{ |
26
|
|
|
use Sortable; |
27
|
|
|
use Sluggable; |
28
|
|
|
use Validation { |
29
|
|
|
makeValidator as baseMakeValidator; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected $table = 'cosmicradiotv_podcast_release_types'; |
33
|
|
|
|
34
|
|
|
protected $slugs = ['slug' => 'name']; |
35
|
|
|
|
36
|
|
|
protected $fillable = ['name', 'slug', 'type', 'filetype']; |
37
|
|
|
|
38
|
|
|
public $timestamps = false; |
39
|
|
|
|
40
|
|
|
public $rules = [ |
41
|
|
|
'name' => ['required'], |
42
|
|
|
'slug' => ['alpha_dash', 'unique:cosmicradiotv_podcast_release_types'], |
43
|
|
|
'type' => ['required', 'in:audio,video,youtube'], |
44
|
|
|
'filetype' => [], |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
/* |
48
|
|
|
* Relations |
49
|
|
|
*/ |
50
|
|
|
|
51
|
|
|
public $hasMany = [ |
52
|
|
|
'releases' => ['CosmicRadioTV\Podcast\Models\Release','delete' => 'true'], |
53
|
|
|
]; |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Returns a custom validator that also validates filetype depending on type |
58
|
|
|
* |
59
|
|
|
* @param $data |
60
|
|
|
* @param $rules |
61
|
|
|
* @param $customMessages |
62
|
|
|
* @param $attributeNames |
63
|
|
|
* |
64
|
|
|
* @return \Illuminate\Validation\Validator |
65
|
|
|
*/ |
66
|
|
|
protected static function makeValidator($data, $rules, $customMessages, $attributeNames) |
67
|
|
|
{ |
68
|
|
|
$validator = self::baseMakeValidator($data, $rules, $customMessages, $attributeNames); |
69
|
|
|
|
70
|
|
|
// Audio & video |
71
|
|
|
$validator->sometimes('filetype', ['required'], function ($input) { |
72
|
|
|
return in_array($input->type, ['audio', 'video']); |
73
|
|
|
}); |
74
|
|
|
|
75
|
|
|
return $validator; |
76
|
|
|
} |
77
|
|
|
} |