Feat: Organize videos by sector
This commit is contained in:
29
plataforma-tutorias/app/Models/Sector.php
Normal file
29
plataforma-tutorias/app/Models/Sector.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\Video;
|
||||
|
||||
class Sector extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'slug',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
public function videos()
|
||||
{
|
||||
return $this->belongsToMany(Video::class, 'video_sector');
|
||||
}
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->hasMany(User::class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
use App\Models\Sector;
|
||||
|
||||
class User extends Authenticatable implements JWTSubject
|
||||
{
|
||||
@@ -16,6 +17,7 @@ class User extends Authenticatable implements JWTSubject
|
||||
'email',
|
||||
'password',
|
||||
'role_id',
|
||||
'sector_id',
|
||||
'created_at',
|
||||
];
|
||||
|
||||
@@ -47,4 +49,9 @@ class User extends Authenticatable implements JWTSubject
|
||||
{
|
||||
return $this->belongsToMany(Workshop::class, 'user_workshop')->withTimestamps();
|
||||
}
|
||||
|
||||
public function sector()
|
||||
{
|
||||
return $this->belongsTo(Sector::class, 'sector_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\Category;
|
||||
use App\Models\Sector;
|
||||
|
||||
class Video extends Model
|
||||
{
|
||||
@@ -84,4 +85,8 @@ class Video extends Model
|
||||
return $this->views()->where('user_id', $user->id)->exists();
|
||||
}
|
||||
|
||||
public function sectors()
|
||||
{
|
||||
return $this->belongsToMany(Sector::class, 'video_sector');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user