Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Holiday extends Model
- {
- protected $table = 'holidays';
- protected $primaryKey = 'holiday_id';
- public $timestamps = false;
- public function dates(){
- return $this->hasOne('AppHolidayDates', 'holiday_id');
- }
- public function images(){
- return $this->hasMany('AppHolidayImages', 'holiday_id');
- }
- public function info(){
- return $this->hasOne('AppHolidayInfo', 'holiday_id');
- }
- public function pricing(){
- return $this->hasOne('AppHolidayPricing', 'holiday_id');
- }
- }
- class HolidayInfo extends Model
- {
- protected $table = 'holiday_info';
- public $timestamps = false;
- protected $primaryKey = 'holiday_id';
- public function holiday(){
- return $this->hasOne('AppHoliday', 'holiday_id');
- }
- }
- $holidays = Holidays::with('info')->get();
- Holidays::where('country', $country)->with('info')->get();
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'country' in 'where clause' (SQL: select * from holidays where country = australia)
- SELECT * from holidays JOIN holiday_info ON holidays.holiday_id = holiday_info.holiday_id
- public function info(){
- return $this->hasOne('AppHolidayInfo', 'holiday_id');
- }
- Holiday::where(your condition)->with('info')->get();
- public function info(){
- return $this->hasOne('AppHolidayInfo', 'holiday_id','holiday_id');
- }
- hasOne($related, $foreignKey, $localKey )
- $holidays = Holiday::where(your condition)->get();
- foreach($holidays as $holiday){
- $holiday->info->youInfoFieldHere
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement