z-song / laravel-admin

Build a full-featured administrative interface in ten minutes
https://laravel-admin.org
MIT License
11.15k stars 2.82k forks source link

hasmany don't work with subform #5689

Open soufianoxx opened 1 year ago

soufianoxx commented 1 year ago

Description:

i have tables Hotel,Hotelchamber,Chambertime class hotel:

`

Class Hotel extends Model{ public function chambers() { return $this->hasMany(Hotelchamber::class,'hotel_id'); }
}

`

and class Hotelchamber:

`class Hotelchamber extends Model {

public function chamber()
{
    return $this->belongsTo(Hotel::class,'hotel_id');
}
public function times()
{
    return $this->hasMany(Chambertime::class);
}

}`

and class Chambertime:

class Chambertime extends Model { public function chamber() { return $this->belongsTo(Hotelchamber::class,'hotelchamber_id'); } }

i want add now hotel with chamber and time, and i use : `

$form->hasMany('chambers', function (Form\NestedForm $subform) { $subform->text('name', ('Type'))->required(); $subform->number('adult', ('Nombre d\'adultes'))->required(); $subform->number('enfant', ('Nombre d\'enfants'))->required(); $subform->hasMany('times', function (Form\NestedForm $sform) { $sform->date('datefrom', ('Du'))->required(); $sform->date('dateto', ('Au'))->required(); $sform->currency('prix', ('Prix'))->symbol('dhs')->required(); }); });

`

but i have this error: `

Call to undefined method App\Hotel::times()

`how i can add time for each chamber of hotel