Adam nick Adam nick - 1 year ago 76
PHP Question

laravel is showing pivot table data also when using eagerloading

I am using eagerloading to fetch many to many relationship data. Here is my code

$sport = Sport::with([

'sport_levels' => function($q) use ($sportId, $schoolId){
$q->select('', 'sport_id', 'name')->where('sport_id', $sportId)->
where('school_id', $schoolId)->get();
->select('id', 'season_id', 'id as sport_id', 'name as sport_name', 'photo as sport_photo', 'record as sport_record')
->where('school_id', $schoolId)->where('id', $sportId)->get();

and the result is


which is also showing the pivot table, how I can hide this?

Answer Source

You can add pivot data by adding that to the list of hidden attributes of your model:

class SportLevel extends Model {
  protected $hidden = [
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download