I have followed the steps for creating tables in Laravel from here.
I keep getting the error in the attached image.
The UserTable.php and Table.php files are below.
app/Http/Livewire/UsersTable.php
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class UsersTable extends Table
{
public function query() : Builder
{
return User::query();
}
public function columns() : array
{
return [
Column::make('name', 'Name'),
Column::make('email', 'Email'),
Column::make('status', 'Status'),
Column::make('created_at', 'Created At'),
];
}
}
app/Http/Livewire/Table.php
<?php
namespace App\Http\Livewire;
use Livewire\Component;
abstract class Table extends Component
{
public function render()
{
return view('livewire.table');
}
public abstract function query() : \Illuminate\Database\Eloquent\Builder;
public abstract function columns() : array;
public function data()
{
return $this
->query()
->get();
}
}
What does this mean? What can I do?
The error means that the model is not sure which Builder you want to use as a type of query, in your case it's Illuminate\Database\Eloquent\Builder
You can just reference it at the top of the class like this:
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Illuminate\Database\Eloquent\Builder;
class UsersTable extends Table
{
public function query() : Builder
{
return User::query();
}
public function columns() : array
{
return [
Column::make('name', 'Name'),
Column::make('email', 'Email'),
Column::make('status', 'Status'),
Column::make('created_at', 'Created At'),
];
}
}