Advertisement
Ostap34PHP

Untitled

Jan 16th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.46 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App;
  4.  
  5. use Illuminate\Database\Eloquent\Model;
  6. use Laravelista\Comments\Commentable;
  7. use OwenIt\Auditing\Auditable;
  8. use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
  9. use Illuminate\Support\Facades\DB;
  10.  
  11. class Lesson extends Model implements AuditableContract
  12. {
  13.     use Commentable, Auditable;
  14.  
  15.     protected $fillable = ['id', 'course_id', 'name', 'video', 'body'];
  16.  
  17.     /**
  18.      * Attributes to include in the Audit.
  19.      *
  20.      * @var array
  21.      */
  22.     protected $auditInclude = [
  23.         'name',
  24.         'video',
  25.         'body',
  26.     ];
  27.  
  28.     public function course()
  29.     {
  30.         return $this->belongsTo('App\Course');
  31.     }
  32.  
  33.     public function exercises()
  34.     {
  35.         return $this->hasMany('App\Exercise');
  36.     }
  37.  
  38.     public static function previous($lesson_id, $course_id)
  39.     {
  40.         $previous = Lesson::where('id', '<', $lesson_id)->orderBy('id', 'desc')->where('course_id', $course_id)->first();
  41.         return $previous;
  42.     }
  43.  
  44.     public static function next($lesson_id, $course_id)
  45.     {
  46.         $next = Lesson::where('id', '>', $lesson_id)->orderBy('id', 'asc')->where('course_id', $course_id)->first();
  47.         return $next;
  48.     }
  49.  
  50.     public static function isCompleted($id)
  51.     {
  52.         $is_completed = DB::table('lesson_user')
  53.                 ->where('user_id', auth()->id())
  54.                 ->where('lesson_id', $id)
  55.                 ->count() > 0;
  56.         return $is_completed;
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement