Okipa / laravel-table

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

Support for Laravel 8 #61

Closed robman2100 closed 3 years ago

robman2100 commented 3 years ago

Can we get laravel 8 supported? This is why I ask and not sure if it has anything to do with it.. I am getting the following error.

Typed property Okipa\LaravelTable\Table::$tableTemplatePath must be string, null used

My Table

namespace App\Tables;
use App\Models\gamedata;
use Okipa\LaravelTable\Abstracts\AbstractTable;
use Okipa\LaravelTable\Table;

class GameTable extends AbstractTable
{
    /**
     * Configure the table itself.
     *
     * @return \Okipa\LaravelTable\Table
     * @throws \ErrorException
     */
    protected function table(): Table
    {
        return (new Table)->model(gamedata::class)
            ->routes([
                'index'   => ['name' => 'gamedatas.index'],
                'create'  => ['name' => 'gamedata.create'],
                'edit'    => ['name' => 'gamedata.edit'],
                'destroy' => ['name' => 'gamedata.destroy'],
            ])
            ->destroyConfirmationHtmlAttributes(fn(gamedata $gamedata) => [
                'data-confirm' => __('Are you sure you want to delete the line ' . $gamedata->database_attribute . ' ?'),
            ]);
    }

    /**
     * Configure the table columns.
     *
     * @param \Okipa\LaravelTable\Table $table
     *
     * @throws \ErrorException
     */
    protected function columns(Table $table): void
    {
        $table->column('game_id')->sortable()->searchable();
        $table->column('gameName')->sortable()->searchable();
        $table->column('created_at')->dateTimeFormat('d/m/Y H:i')->sortable();
        $table->column('updated_at')->dateTimeFormat('d/m/Y H:i')->sortable();
    }

    /**
     * Configure the table result lines.
     *
     * @param \Okipa\LaravelTable\Table $table
     */
    protected function resultLines(Table $table): void
    {
        //
    }

}

My Controller

public function index(Request $request)
    {
        $table = (new GameTable)->setup();
        return view('admin-games.index', compact('table'));
    }
Okipa commented 3 years ago

@robman2100 Laravel 8 is supported since https://github.com/Okipa/laravel-table/releases/tag/3.0.0.

I'm pretty sure this has nothing to do with L8 support but may be related to your implementation.

The attribute default value is loaded here: https://github.com/Okipa/laravel-table/blob/master/src/Traits/Table/HasTemplates.php#L221

Your error is saying that this attribute has no value, this is why I suppose this error is related to your config file which may be incorrect. Please check with https://github.com/Okipa/laravel-table/blob/master/config/laravel-table.php.

robman2100 commented 3 years ago

Yes it is because laravel supports php 7.3 and up.. I have upgraded my environment to 7.4. This is where the error comes into play. I have the config in my Config folder and it looks exactly like what you have on that last link.

robman2100 commented 3 years ago

This is my Laravel-Tables config located in my config folder. `<?php

return [

/** Set the default classes for each part of the table. */
'classes' => [
    'container' => ['table-responsive'],
    'table' => ['table-borderless'],
    'tr' => ['border-bottom'],
    'th' => ['align-middle'],
    'td' => ['align-middle'],
    'results' => ['table-secondary'],
    'disabled' => ['table-danger', 'disabled'],
],

/** Set all the action icons that are used on the table templates. */
'icon' => [
    'rows_number' => '<i class="fas fa-list-ol"></i>',
    'sort' => '<i class="fas fa-sort fa-fw"></i>',
    'sort_asc' => '<i class="fas fa-sort-up fa-fw"></i>',
    'sort_desc' => '<i class="fas fa-sort-down fa-fw"></i>',
    'search' => '<i class="fas fa-search"></i>',
    'validate' => '<i class="fas fa-check"></i>',
    'info' => '<i class="fas fa-info-circle fa-fw"></i>',
    'reset' => '<i class="fas fa-undo fa-fw"></i>',
    'create' => '<i class="fas fa-plus-circle fa-fw "></i>',
    'show' => '<i class="fas fa-eye fa-fw"></i>',
    'edit' => '<i class="fas fa-edit fa-fw"></i>',
    'destroy' => '<i class="fas fa-trash fa-fw"></i>',
],

/** Set the table default behavior. */
'behavior' => [
    'rows_number' => 20,
    'activate_rows_number_definition' => true,
],

/** Set the default view path for each component of the table. */
'template' => [
    'table' => 'vendor.laravel-table.bootstrap.table',
    'thead' => 'vendor.laravel-table.bootstrap.thead',
    'rows_searching' => 'vendor.laravel-table.bootstrap.rows-searching',
    'rows_number_definition' => 'vendor.laravel-table.bootstrap.rows-number-definition',
    'create_action' => 'vendor.laravel-table.bootstrap.create-action',
    'column_titles' => 'vendor.laravel-table.bootstrap.column-titles',
    'tbody' => 'vendor.laravel-table.bootstrap.tbody',
    'show_action' => 'vendor.laravel-table.bootstrap.show-action',
    'edit_action' => 'vendor.laravel-table.bootstrap.edit-action',
    'destroy_action' => 'vendor.laravel-table.bootstrap.destroy-action',
    'results' => 'vendor.laravel-table.bootstrap.results',
    'tfoot' => 'vendor.laravel-table.bootstrap.tfoot',
    'navigation_status' => 'vendor.laravel-table.bootstrap.navigation-status',
    'pagination' => 'vendor.laravel-table.bootstrap.pagination',
],

];`

robman2100 commented 3 years ago

It looks like it is not grabbing my config files.. But the config file exists.. Im not sure why it is doing this

robman2100 commented 3 years ago

I manually entered the config info direct. And it seems like it wants to work... but then I come back to gamedatas.view not found now.. not sure why it is creating a plural view on the end of my view. the route works and the view is for sure there. Definitly think your code is not setup for php 7.4

Okipa commented 3 years ago

Well, this package requires PHP 7.4 and dropped support for earlier versions since V2. It is also running with 20+ PHP 7.4 production projects without any issue.

Did you try a fresh install on a new Laravel projet ?

I have upgraded my environment to 7.4. => you also should check your environment to make sure PHP 7.4 is actually running, this could be the source of your issue.

robman2100 commented 3 years ago

C:\xampp\htdocs\jindo\jindo>php -v PHP 7.4.10 (cli) (built: Sep 1 2020 16:52:39) ( ZTS Visual C++ 2017 x64 ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies

robman2100 commented 3 years ago

Both CLI And My Xampp are running 7.4

I am unsure why it is doing this.. I didnt upgrade my laravel project. It is a new project based off Laravel Auth() build.

And I am able to do manual tables ect and passing on the same view I try to initialize your Plugin.. Im bummed because I really wanted to use this.

robman2100 commented 3 years ago

Alright I have got it working now.. However I have a weird issue where it is showing #validation.attributes.MyColumName for the titles

robman2100 commented 3 years ago

I fixed it by assigning title. ->title('ID') Thanks!

nizar0x1f commented 3 years ago

I have the same issue how did you resolve the Typed property error ?