mardi 7 février 2017

Remove one to one relationship in Laravel

I'm using Laravel 5.2 and I have created a one to one relation as follows.

 $driver    = Driver::find($driver->id);
 $vehicle = Vehicle::find($vehicleId);
 $vehicle->driver()->associate($vehicle);
 $vehicle->save();

This works perfectly. In some scenarios I need to break this relationship by removing the particular driver from the vehicle.

$driver    = Driver::find($driver->id);
$vehicle = Vehicle::find($vehicleId);
$vehicle->driver_id->NULL;
$vehicle->save();

But this doesn't work. I have tried some other approaches.

$vehicle->driver()->delete();

$vehicle->driver()->dissociate();

Nothing is working in my case. Could any please give a hint, what's wrong in there.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2jXG9o7
via IFTTT

Aucun commentaire:

Enregistrer un commentaire