Looks like the accepted answer is not really the case. I was thinking about querying from within the livewire controller and I too found it weird that I would have to do this query a second time when I already had it.
The issue with the original poster was that he was passing a non existent variable into the livewire view, passing in $deals (which is scoped to the render method) instead of the variable scoped to the class: $this->deals.
I can pass a collection from my laravel controller into a normal blade view and from there inject the variable as a parameter into the livewire component, then from this component's controller class into the livewire view and it is parsed correctly without needing to convert it into an array beforehand like one of the comments mentioned above. Everything should just work.
Blade View called by Laravel controller:
<x-layouts.admin>
<livewire:projects-dashboard :projects="$projects">
</x-layouts.admin>
Livewire Controller:
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class ProjectsDashboard extends Component
{
public $projects; // livewire auto-assigns component parameter to this variable
public function render()
{
return view('livewire.projects-dashboard', [
'projects' => $this->projects, // passing in variable into livewire view
]);
}
}
Livewire View:
@foreach($projects as $project)
<a href="projects/{{ $project->slug }}">{{ $project->name }}</a>
@endforeach