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
1,535 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,840 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 9,777 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,840 points
3,884 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,840 points
2,573 views
+1 vote
1 answer

How to load blade or php content into a view via ajax/jquery in laravel?

Hello @kartik, Assuming you're using jQuery... create a route ...READ MORE

answered Apr 14, 2020 in Laravel by Niroj
• 82,840 points
28,411 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
23,449 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18, 2020 in Laravel by Niroj
• 82,840 points
3,141 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
3,171 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23, 2020 in Laravel by Niroj
• 82,840 points
45,599 views
0 votes
1 answer

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

Hello @kartik, Your response must return some sort ...READ MORE

answered Sep 24, 2020 in Laravel by Niroj
• 82,840 points
5,977 views
0 votes
1 answer

Error: 'Unchecked runtime.lastError: The message port closed before a response was received' chrome issue?

uninstall chrome extension one by one and ...READ MORE

answered Sep 25, 2021 in Laravel by Nitish Verma

edited Mar 5 53,838 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP