Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

alrocha's avatar

Array to string conversion Error

Hi! I'm just doing a normal search function I was following the tutorial of Search elementls and when I was already in my controller I got the query and it fais with this error:

ErrorException in EventsController.php line 171: Array to string conversion

public function search(Request $request)

{
        $query = $request->all();
        $resutl = DB::table('events')->where('name','LIKE', '.%'. $query.'%.')->get();
   dd($resutl);
    }

public function search(Request $request)

{
        $query = $request->all();
        $events = Event::where('name','LIKE', ".%$query%.")->get();
    
        dd($events);
    }

I've got the same error both times, any clue?

PD: the url query looks like it has some crappy added, when I was trying to look for matches with "ie" I've got this.

192.168.1.112:5555/events/%7Bquery%7D?q=ie

Thanks in advance.

0 likes
2 replies
pmall's avatar
pmall
Best Answer
Level 56

This is an array : $request->all();. You cant concatenate it with a string.

alrocha's avatar

Indeed solved with $query = $request->get('q'); thank you!!!! :)

Please or to participate in this conversation.