I'm using Laravel 5.8 to build a babysitting site. I have 4 tables with different relationships as below:
The relationships are:
Babysitter->hasMany(session)
Sessions->hasOne(Review)
Sessions->hasOne(Kids)
Sessions->hasOne(Babysitter)
Sessions->hasOne(Parent)
I want to achieve 2 things:
First one
I want to show this result when listing all babysitters. I'm showing this information for each babysitter:
See here what I couldn't achieve
This is my code
Sitters::where('Status', 'active')->where('Verified', 1)->get();
Second one
Also, I've tried to show kids name with parent review as shown here:
This is what i'm using
Sessions::select('Reviews.*', 'Sessions.Parent_id')->join('Reviews', 'Reviews.Session_id', '=', 'Sessions.id')->with('owner')->where('Trainer_id', session('user')->Id)->where('Status', '=', 'complete')->with('owner')->orderBy('Sessions.id', 'DESC')->get();
Here is Session.php Model
public function owner(){
return $this->belongsTo('App\Models\Parents', 'Parent_id');
}
HasManyrelation isbelongsTonotHasOne.Sessions->hasOne(Review),Sessions->belongsTo(Kids),Sessions->belongsTo(Babysitter),Sessions->belongsTo(Parent). Try see if this will allow you to query build using the relations.SessionsandReviewscan be merged into the same table withnullablereview's fields. but that's just a preferencesesstionorsession? Are those typos? Plus, it's better including relevant parts of your code here than putting inline image links. The links are very distracting.