Level 1
Jun 13, 2024
1
Level 1
Updating two models HasMany Relationship
Hello
Have to models Owner and Car Need help with code for updating car entries in Car Model from Owner Controller
Form is based on "Invoice Dynamic Table" Changed owner view edit form to add another form for adding/editing car entries. Based on Invoice Dynamic Table.
Error:
Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::attach()
Owner Model, Using Has Many because an owner will have multiple car but a car will not have multiple owner.
class Owner extends Model
{
public function cars()
{
return $this->hasMany(Car::class);
}
}
Car Model
class Car extends Model
{
public function owner()
{
return $this->belongsTo(Owner::class);
}
}
Owner Controller ( Need help here..)
class OwnerController extends Controller
{
public function update(UpdateOwnerRequest $request, Owner $owner)
{
$owner->update($request->all());
return redirect()->route('owner.index');
}
Thank You
Please or to participate in this conversation.