Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0

Hy !'

do you use the methode name inside with() methode ??


class Amenitie extends \Eloquent
{

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'amenities';

    /**
     * @var array
     */
    protected $fillable = ['*'];

    /**
     * Indicates if the model should be timestamped.
     *
     * @var bool
     */
    public $timestamps = false;

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function hotels()
    {
        return $this->belongsToMany('\Grade\Models\Hotel', 'hotels_amenities', 'amenitie_id', 'hotel_id');
    }

}


class Hotel extends \Eloquent
{

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'hotels';

    /**
     * @var array
     */
    protected $fillable = ['*'];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function amenities()
    {
        return $this->belongsToMany('\Grade\Models\Amenitie', 'hotels_amenities', 'hotel_id', 'amenitie_id');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function rooms()
    {
        return $this->hasMany('\Grade\Models\Room', 'hotel_id');
    }
}

so ur call shold be like this :


Route::get('test', function () {

    return \Grade\Models\Amenitie::with(['hotels','hotels.rooms'])->first();
});

0

what is clientGroups.Profiles is that the name or the relationship and global scope.

eg: If I have a model called $users and it related to roles and roles has a global scope called adminUsers

I would

User::with('roles')->adminUsers()->get()

I would not

User::with('role.adminUsers')->get()

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

KevinM86 kevinm86 Joined 3 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.