Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- use Laravelista\Comments\Commentable;
- use OwenIt\Auditing\Auditable;
- use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
- use Illuminate\Support\Facades\DB;
- class Lesson extends Model implements AuditableContract
- {
- use Commentable, Auditable;
- protected $fillable = ['id', 'course_id', 'name', 'video', 'body'];
- /**
- * Attributes to include in the Audit.
- *
- * @var array
- */
- protected $auditInclude = [
- 'name',
- 'video',
- 'body',
- ];
- public function course()
- {
- return $this->belongsTo('App\Course');
- }
- public function exercises()
- {
- return $this->hasMany('App\Exercise');
- }
- public static function previous($lesson_id, $course_id)
- {
- $previous = Lesson::where('id', '<', $lesson_id)->orderBy('id', 'desc')->where('course_id', $course_id)->first();
- return $previous;
- }
- public static function next($lesson_id, $course_id)
- {
- $next = Lesson::where('id', '>', $lesson_id)->orderBy('id', 'asc')->where('course_id', $course_id)->first();
- return $next;
- }
- public static function isCompleted($id)
- {
- $is_completed = DB::table('lesson_user')
- ->where('user_id', auth()->id())
- ->where('lesson_id', $id)
- ->count() > 0;
- return $is_completed;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement