<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Event extends Model
{
    public function bookings()
    {
        return $this->morphMany('App\Booking', 'bookable');
    }

    public function courses()
    {
        return $this->hasMany('App\Course');
    }

    public function user()
    {
    return $this->belongsTo('App\User');
    }

    public function course($p,$l)
    {
        $courses = $this->courses;

        foreach ($courses as $c)
        {
            if ($c->periode == $p && $c->level == $l)
            {
                return $c;
            }
        }

        return false;
    }
}
