As the error states, associate accepts an eloquent model as first parameter, not a string. You need to pass it a colaborador model, not id.
Ok, nice information.
But what should I use to better accomplish my need? Is really instantiating an colaborador object? Or there is a simplest way?
Of course not, but since there is no
disassociate method you need to set the FK value to null:
$veiculo->colaborador()->associate('NULL')->save(); // change to: $veiculo->colaborador_id = null; $veiculo->save();
Obviously this will work only if you have set that column as nullable.
Hello, I tried that, the field is nullable. But its not setting the field to NULL.
Like this: $veiculo = Veiculo::find($id); $colid = $veiculo->colaborador_id;
$colaborador = Colaborador::find($colid); $colaborador->veiculo_id = null; $colaborador->save(); $veiculo->colaborador_id = null;
And there is no change at that field.
You are setting a value on colaborador and trying to output a value on veiculo...
Sign in to participate in this thread!
We'd like to thank these amazing companies for supporting us
The Laravel portal for problem solving, knowledge sharing and community building.