I have a Many-to-Many relation and want to store data. However, I get a Call to a member function sync() on null problem. I think everything is good, therefore I can absolutely not say what the problem is!
Here are my Models
class Service extends Model
{
public function locations(){
$this->belongsToMany('aquaact\Location','location_service','service_id','location_id');
}
}
class Location extends Model
{
public function services(){
$this->belongsToMany('aquaact\Service','location_service','location_id','service_id');
}
}
Here is my store function that is called in the LocationController. The Post data shows, that $request->services has data.
public function store(Request $request)
{
...
$location = new Location;
...
$location->save();
$location->services()->sync($request->services, false);
...
}
The error is showing that the sync line has an error. What can I do?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2iVjTYA
via IFTTT
Aucun commentaire:
Enregistrer un commentaire