BrownieCoffee
3 months ago

htmlspecialchars() expects parameter 1 to be string, object given

Posted 3 months ago by BrownieCoffee

Hello there,

I have a problem to fix this error.

I want to use my datas from the "services" table. I did this in my controller to get all datas:

use Illuminate\Support\Facades\DB;



    public function create(){


        $services = DB::table('services')->get([
            'id', 'name'
        ]);

        dump($services);

        return view ('request.create', compact('services'));

    }

I'm trying to do a foreach for get id and name

<select class="form-control" id="needed-service" name="needed-service">
       <option hidden disabled selected value="">Selectionner un service</option>
             @foreach ($services as $keyService => $service)
                    <option value="{{$keyService}}">{{$service}}</option>
             @endforeach
       <option>Cours de conduite</option>
</select>

but I have this error but I can not fix this problem...

htmlspecialchars() expects parameter 1 to be string, object given (View: /var/www/html/ourSwapServices/resources/views/request/create.blade.php)

Can you help me please ?

Thank you in advance and see you soon!

Please sign in or create an account to participate in this conversation.