Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App;
- use Carbon\Carbon;
- use Illuminate\Database\Eloquent\Model;
- class Film extends Model
- {
- protected $fillable = ['title','plot','user_id','released_at'];
- protected $dates = ['released_at'];
- //add the full time to the released at attribute (date mutators).
- public function setReleasedAtAttribute($date)
- {
- $this->attributes['released_at'] = Carbon::createFromFormat('Y-m-d',$date);
- }
- public function getReleasedAtAttribute($data)
- {
- return (new Carbon($data));
- }
- /** A scope that gets the released film records only
- * @param $query
- */
- public function scopeReleased($query)
- {
- $query->where('released_at','<=',Carbon::now());
- }
- /** A scope that gets the unreleased film records only
- * @param $query
- */
- public function scopeUnreleased($query)
- {
- $query->where('released_at','>',Carbon::now());
- }
- /*
- *A laravel relationship - one to many, get the owner of a movie
- *
- */
- public function owner()
- {
- return $this->belongsTo('App\User');
- }
- /*
- *A laravel relationship - Many to Many, get the associated genres of the specified movie
- *
- */
- public function genres()
- {
- return $this->belongsToMany('App\Genre');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement