Hi Donny5300,
If you using the Companies_Schedules as a pivot table of companies and schedules you can make it using your models you can tell to them how relate with the others tables:
class Company extends Eloquent{
protected $table = "companies";
public function schedules{
return $this->hasMany('Schedule'); //you can specity more options to this method.
}
}
class Schedule extends Eloquent{
protected $table = "schedules";
public function company{
return $this->belongsTo('Company'); //you can specify more options to this method
}
}
class CompanySchedule extends Eloquent{
protected $table = "companies_schedules";
public function company{
return $this->belongsTo('Company'); //you can specify more options to this method
}
public function schedule{
return $this->belongsTo('Schedule'); //you can specify more options to this method
}
}
You can find more examples in the official documentation of Laravel, you can use pivot tables.
If anybody can get us more example of this question because I could be wrong.
Thanks so much.
Hope it helps you.
But how does i have to work it out in the controller? In doctrine EM i knew it works with getting both repo's and then attach them to each other
Outside of the Model you ned to call the methods of the models, in example:
class SchedulesController extends BaseController {
public function getCompany{
return Schedule::has('company')->get();
}
}
And in the Routes.php you can use as follow:
Route::get('companyschedules', 'SchedulesController@getCompany'){
});
Hope it helps you..
I know how to get the results, but what i dont get is how to insert the company and schedule in the joined table i created for it. In normal PHP i could do
$sql = "INSERT INTO company_schedule ('user_id', 'company_id') VALUES (1 , 15); $execute = mysql_query($sql);
But how does i do that in Eloquent?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community