college-courses/app/Models/Course.php

31 lines
524 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Course extends Model
{
use HasFactory;
protected $fillable = [
'name', 'user_id', 'slug'
];
public function lessons()
{
return $this->hasMany(Lesson::class);
}
public function getRouteKeyName()
{
return 'slug';
}
public function getLesson($slug)
{
return $this->lessons()->where('slug', $slug)->first();
}
}