Skip to content

Instantly share code, notes, and snippets.

@YordiLorenzo
Created November 23, 2014 11:02
Show Gist options
  • Save YordiLorenzo/0bcf95e4b3f09f3f9f92 to your computer and use it in GitHub Desktop.
Save YordiLorenzo/0bcf95e4b3f09f3f9f92 to your computer and use it in GitHub Desktop.
Portfolio - Schippersagenda sample
/**
* Relational model for boat trips with Laravel's Eloquent
*/
<?php namespace Schippersagenda\Models;
use \Eloquent;
class Trip extends Eloquent {
/**
* @access protected
* Table trips
* @var string
*/
protected $table = "trips";
/**
* Fillable column names
* @var Array
*/
protected $fillable = ['start_time', 'end_time', 'date','boat_id','captain_id','type_id'];
/**
* Type relation
* @return Type
*/
public function type(){
return $this->hasOne('Schippersagenda\Models\Type', 'id', 'type_id')->select(['id', 'name']);
}
/**
* Boat relation
* @return Boat
*/
public function boat(){
return $this->hasOne('Schippersagenda\Models\Boat', 'id', 'boat_id');
}
/**
* Captain relation
* @return Captain
*/
public function captain(){
return $this->hasOne('Schippersagenda\Models\User', 'id', 'captain_id')->select(['id', 'email', 'username', 'first_name', 'last_name']);
}
/**
* Message relation
* @return Message
*/
public function message(){
return $this->hasOne('Schippersagenda\Models\Message', 'id', 'message_id');
}
/**
* Date mutator to reflect local readable timestamp
* @param Date $value
* @return Date
*/
public function getDateAttribute($value){
$date = \Carbon\Carbon::parse($value);
return ucfirst($date->formatLocalized('%A %d %B %Y'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment