Okipa / laravel-table

Generate tables from Eloquent models.
MIT License
532 stars 64 forks source link

Route [templates.users.index] not defined #53

Closed felloz closed 3 years ago

felloz commented 4 years ago

Hello, im recieving this error:

Route [templates.users.index] not defined. (View: E:\Laravel\vue\resources\views\vendor\laravel-table\bootstrap\rows-searching.blade.php)

My routes:

Route::get('/user', 'UsersController@index')->name('user.index');

UsersTable:

<?php

namespace App\Tables;

use Okipa\LaravelTable\Abstracts\AbstractTable;
use Okipa\LaravelTable\Table;
use App\User;

class UsersTable extends AbstractTable
{
    protected function table(): Table
    {
        return (new Table)->model(User::class)
            ->routes([
                'index' => ['name' => 'users.index'],
                'create' => ['name' => 'user.create'],
                'edit' => ['name' => 'user.edit'],
                'destroy' => ['name' => 'user.destroy'],
            ])
            ->destroyConfirmationHtmlAttributes(fn (User $user) => [
                'data-confirm' => __('Are you sure you want to delete the user :name ?', [
                    'name' => $user->name
                ])
            ]);
    }

    protected function columns(Table $table): void
    {
        $table->column('id')->sortable(true);
        $table->column('name')->sortable()->searchable();
        $table->column('email')->sortable()->searchable();
        $table->column('created_at')->dateTimeFormat('d/m/Y H:i')->sortable();
        $table->column('updated_at')->dateTimeFormat('d/m/Y H:i')->sortable();
    }
}

Controller

<?php

namespace App\Http\Controllers;

use \Illuminate\View\View;
use \App\Tables\UsersTable;
use Illuminate\Http\Request;

class UsersController extends Controller
{
    public function index(): View
    {
        $table = (new UsersTable)->setup();

        return view('templates.users.index', compact('table'));
    }
}
Okipa commented 3 years ago

Hi @felloz,

I close this as it seems that this is not related to this package : you are using the users.index route in the table ->routes() method but the one you have declared is named user.index.

Feel free to reopen if the issue is finally related to the package.