Error UnexpectedValueException The Response content must be a string or object implementing toString object given

0 votes

I have a controller where I want to combine data from multiple tables with parallel structures. What I want to end up with in the end is one object I can return from the controller so I can parse it in Backbone.

I want to do something like this:

public function index()
{
    $mc = MainContact::where('verified', '=', '1')->get();
    $sm = SendMessage::where('verified', '=', '1')->get();

    $obj = (object) array_merge((array) $mc, (array) $sm);
    return $obj;
}

However,returns the following error in Laravel:

UnexpectedValueException: The Response content must be a string or object implementing
 __toString(), "object" given.

How do I implement this method in Laravel?

Nov 12, 2020 in Laravel by kartik
• 37,520 points
2,061 views

1 answer to this question.

0 votes

Hii,

You can simply use:

$new_collection = $collection->merge($other_collection).

Hope it helps!!

answered Nov 12, 2020 by Niroj
• 82,800 points

Related Questions In Laravel

0 votes
1 answer

Error:The bootstrap/cache directory must be present and writable' error after update

I solved the error by copying an ...READ MORE

answered Jun 24, 2022 in Laravel by Ishmael Mavor Raines

edited Mar 5 11,329 views
0 votes
1 answer

Error:Object of class Illuminate\Database\MySqlConnection could not be converted to string

Hello @kartik, The use keyword is what you need: $id = ...READ MORE

answered Sep 24, 2020 in Laravel by Niroj
• 82,800 points
4,538 views
0 votes
1 answer

Getting the query builder to output its raw SQL query as a String?

Hello, DB::QueryLog() only work after you execute the query $builder->get(). ...READ MORE

answered Mar 30, 2020 in Laravel by Niroj
• 82,800 points
3,081 views