I would suggest moving the query from your view to your controller instead, and pass it to the view. Let the controller talk to the db.
Oct 27, 2025
13
Level 1
Duplicate Query when Passing Eloquent Query to Blade Component
I have the following select blade component:
@props([
'id' => '',
'options' => array(),
])
<select name="{{ $id }}" id="{{ $id }}">
@foreach($options as $value => $name)
<option value="{{ $value }}">{{ $name }}</option>
@endforeach
</select>
I'm then using this component as follows:
<x-input.field-select id="company_id" :options="\App\Models\Company::orderBy('name')->pluck('name', 'id')->toArray()" />
When debugging, I'm finding that the query is executing twice, but I don't understand why?
Amending my usage to the following solves the issue, but I'd like to understand why the above doesn't work as I think it looks cleaner:
@php
$options = \App\Models\Company::orderBy('name')->pluck('name', 'id')->toArray();
@endphp
<x-input.field-select id="company_id" :options="$options" />
Please or to participate in this conversation.