|
3 | 3 | namespace App\Models\Channel;
|
4 | 4 |
|
5 | 5 | use App\Models\Channel\Traits\VideoRelationship;
|
| 6 | +use App\Models\HasSchemalessAttributes; |
6 | 7 | use Cklmercer\ModelSettings\HasSettings;
|
7 | 8 | use Illuminate\Database\Eloquent\Factories\HasFactory;
|
8 | 9 | use Illuminate\Database\Eloquent\Model;
|
| 10 | +use Illuminate\Support\Facades\Storage; |
9 | 11 | use Jcc\LaravelVote\Traits\Votable;
|
10 | 12 | use Overtrue\LaravelLike\Traits\Likeable;
|
11 | 13 | use CyrildeWit\EloquentViewable\InteractsWithViews;
|
12 | 14 | use CyrildeWit\EloquentViewable\Contracts\Viewable;
|
13 | 15 | use Cog\Contracts\Ban\Bannable as BannableContract;
|
14 | 16 | use Cog\Laravel\Ban\Traits\Bannable;
|
| 17 | +use Spatie\SchemalessAttributes\SchemalessAttributesTrait; |
| 18 | +use Illuminate\Database\Eloquent\Builder; |
15 | 19 |
|
16 | 20 | class Video extends Model implements Viewable, BannableContract
|
17 | 21 | {
|
18 |
| - use HasFactory, Likeable, Votable, VideoRelationship, InteractsWithViews, HasSettings, Bannable; |
| 22 | + use HasFactory, Likeable, Votable, VideoRelationship, |
| 23 | + InteractsWithViews, HasSettings, Bannable, SchemalessAttributesTrait; |
19 | 24 |
|
20 | 25 | protected $fillable = [
|
21 | 26 | 'tus_id', 'media_id', 'name', 'description', 'disk', 'path',
|
22 | 27 | 'thumbnail_url', 'file_size', 'file_type', 'duration', 'progress', 'status',
|
23 |
| - 'streaming_url' |
| 28 | + 'streaming_url', 'type', 'extra_attributes' |
24 | 29 | ];
|
| 30 | + |
| 31 | + protected $schemalessAttributes = [ |
| 32 | + 'extra_attributes', |
| 33 | + ]; |
| 34 | + |
| 35 | + public function scopeWithExtraAttributes(): Builder |
| 36 | + { |
| 37 | + return $this->extra_attributes->modelScope(); |
| 38 | + } |
| 39 | + |
| 40 | + public function getVideoSourceAttribute() |
| 41 | + { |
| 42 | + return $this->type == 'upload' ? Storage::disk($this->disk)->url($this->streaming_url) : env('RTMP_HOST') . $this->streaming_url; |
| 43 | + } |
25 | 44 | }
|
0 commit comments