0

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');
    }
Mark
  • 151
  • 1
  • 1
  • 13
  • can u post the relationship method? – TsaiKoga Jan 23 '20 at 11:24
  • @TsaiKoga just updated and added them, pretty basic belongsTo relationships, nothing fancy. The issue sits with TNTSearch trying to index the new model entity but I assume it's trying to pass the relationships in as a string when they are an array. I'm not sure how I can get it to ignore the relationships. – Mark Jan 23 '20 at 11:27

0 Answers0