I am trying to use laravel livewire to create a dynamic dependent drop down list. So I have created a livewire component named assignment.
assignment.blade.php
<div>
<div class="row mb-4">
<label for="category" class="col-md-4 col-form-label text-md-end">Category</label>
<div class="col-md-6">
<select name="category" id="category" class="form-select col-md-6">
<option value="null">Select category</option>
@foreach ($categories as $item)
<option value="{{$item->id}}">{{$item->name}}</option>
@endforeach
</select>
</div>
</div>
<div class="row pt-4">
<button class="btn btn-warning text-white" wire:loading.attr="disable">Add New Product</button>
<div wire:loading>
Hold on...
</div>
</div>
</div>
assignment.php
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Category;
class Assignment extends Component
{
public function render()
{
return view('livewire.assignment', [
'Category' => Category::all()
]);
}
}
The livewire component is embedded on the create.blade.php. Here is a snippet
</div>
<livewire:assignment />
<div class="row mb-4">
<label for="subcategory" class="col-md-4 col-form-label text-md-end">Sub Category</label>
<div class="col-md-6">
<select name="subcategory" id="subcategory" class="form-select col-md-6">
<option value="null">Select subcategory</option>
<option value="wine">Wine</option>
<option value="whisky">Whisky</option>
Here is my productscontroller function that renders the view
public function create()
{
return view('products.create');
}
routes
Route::get('/explore', [App\Http\Controllers\ConnectsController::class, 'index']);
Route::get('/p/create', [App\Http\Controllers\ProductsController::class, 'create']);
Route::post('/p', [App\Http\Controllers\ProductsController::class, 'store']);
I am getting the following error: syntax error, unexpected end of file. What could be the issue?
There is a typo in assignment.blade.php. @enforeach should be @endforeach. I had to post this as answer as could not post this as comment.