presleyd / alpinejs-select

85 stars 19 forks source link

Can't find variable: AlpineSelect #2

Closed eddyinet closed 3 years ago

eddyinet commented 3 years ago

This looks fantastic! While attempting to integrate it was getting errors about the data prop so I created a new Laravel component using

php artisan make:component SelectSearch

So that the SelectSearch.php component file is created:

` namespace App\View\Components;

use Illuminate\View\Component;

class SelectSearch extends Component { public $data;

public function __construct($data)
{
    $this->data = $data;
}

public function render()
{
    return view('components.select-search');
}

} `

Once this was done I was able to render the component but now the console comes back with:

Can't find variable: AlpineSelect

I'm assuming I wasn't supposed to create the component that way... thoughts on what I missed?

Thanks!

eddyinet commented 3 years ago

OK I added: @stack('body_scripts') to my index blade. Renders now.

Data isn't being populated just yet. In my livewire component I'm just initializing:

public $data = [1 => "First Option", 2 => "Second Option"];

presleyd commented 3 years ago

What's in the view for that component? If you added my file to say 'resource/views/components/select-search.blade.php' you should use it in your Livewire component like this:

If you don't wire:model here you won't be able to get the selected option back out. I do not render an html