When trying to replicate a model with relationships TNTSearch fails with mb_strtolower() expects parameter 1 to be string, array is given
error.
This only happens when Laravel replicates a model with relationships and then tries to save it. This behavior doesn't happen for models without relationships. Same outcome for save() and push()
Example:
This works fine as expected.
$inventory = Inventory::where(['id' => $order->inventory_id])->first();
$new = $inventory->replicate();
$new->push();
TNTSearch will fail with the following:
$inventory = Inventory::with(['type', 'form'])->where(['id' => $order->inventory_id])->first();
$new = $inventory->replicate();
$new->push();
So the error is obvious enough, it's a basic PHP error but how do I get around the error when trying to replicate a model's relationships as well? Is it a case of saving the model first and then trying to replicate all it's relationships individually after the initial replicate?
UPDATE: adding the relationship's method as requested. Pretty basic and nothing fancy.
app/Inventory.php
public function type()
{
return $this->belongsTo('App\Type');
}
public function form()
{
return $this->belongsTo('App\Form');
}