I an following an on-line tutorial using Laravel - Livewire. I have spent countless hours in trying to fix an and Undefined variable error. The code and structure is as follows:
Models DirectoryCategory.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class DirectoryCategory extends Model
{
use HasFactory;
}
Livewire Class AdminDashboardDirectoryCategoryComponent.php
<?php
namespace App\Http\Livewire\Admin;
use App\Models\DirectoryCategory;
use Directory;
use Livewire\Component;
use Livewire\WithPagination;
class AdminDashboardDirectoryCategoryComponent extends Component
{
use WithPagination;
public function render()
{
$dcategories = DirectoryCategory::paginate(10);
return view('livewire.admin.admin-dashboard-directory-category-component',['dcategories'=>$dcategories])->layout('livewire/admin.admin-dashboard-directory-category-component');
}
}
view admin-dashboard-directory-category-component.blade.php
<thead>
<tr>
<th>#</th>
<th>Image</th>
<th>Group</th>
<th>Title</th>
<th>Slug</th>
<th>Desc</th>
</thead>
<tbody>
@foreach($dcategories as $dcategory)
<tr>
<td>{{$dcategory->id}}</td>
<td><img src="{{asset('frontend.assets/images/dir_categories')}}/{{$dcategory->image}}" width="60" /></td>
<td>{{$dcategory->group}}</td>
<td>{{$dcategory->title}}</td>
<td>{{$dcategory->slug}}</td>
<td>{{$dcategory->desc}}</td>
</tr>
@endforeach
</tbody>