sebastienheyd / boilerplate

Laravel AdminLTE 3 Boilerplate package with blade components, users, roles and permissions management
MIT License
219 stars 66 forks source link

in_array(): Argument #2 ($haystack) must be of type array, null given #49

Closed cod3rshotout closed 2 years ago

cod3rshotout commented 2 years ago

Hi,

If you browse the route: /admin/users, you will get this error:

Immagine 2022-01-26 115850

which is caused by that line: @if(in_array('filters', $datatable->buttons)), in particular UsersDatatable doesn't have any buttons, so this will throw an exception, I temporary fixed this using:

$this->permissions('users_crud')
            ->locale([
                'deleteConfirm' => __('boilerplate::users.list.confirmdelete'),
                'deleteSuccess' => __('boilerplate::users.list.deletesuccess'),
            ])
            ->buttons([]) // MUST BE SPECIFIED
            ->order('created_at', 'desc')
            ->stateSave();

Also, I guess that this line:

$userModel = config('boilerplate.laratrust.user.providers.users.model');

should be:

$userModel = config('boilerplate.laratrust.user');

otherwise this will throw a type exception on ajax load

sebastienheyd commented 2 years ago

Hi,

Are you using the latest version ?

cod3rshotout commented 2 years ago

@sebastienheyd yes, also I noticed that since the latest version I doesn't have any filters on the DataTables columns

sebastienheyd commented 2 years ago

You don't have filters because you set buttons([]).

As you can see in Datatable.php - ln. 34, filters is set by default.

Also in the latest version of UsersDatatable.php - ln. 16, $userModel is equal to config('boilerplate.auth.providers.users.model')

Are you sure you have the latest version? Also check your overloads if you have any.

cod3rshotout commented 2 years ago

You don't have filters because you set buttons([]).

As you can see in Datatable.php - ln. 34, filters is set by default.

Also in the latest version of UsersDatatable.php - ln. 16, $userModel is equal to config('boilerplate.auth.providers.users.model')

Are you sure you have the latest version? Also check your overloads if you have any.

I guess I found the problem about the $userModel, I've executed the scaffhold command to customize the boilerplate, but seems that some files like UsersDatatable aren't inserted in my solution (I don't know if it was wanted or was it an oversight?)

So in UsersDatatable I have:

use Sebastienheyd\Boilerplate\Models\User;

class UsersDatatable extends Datatable
{
    public $slug = 'users';

    public function datasource()
    {
        $userModel = config('boilerplate.auth.providers.users.model');

and in myapp/config/boilerplate/auth I have:

    'providers'     => [
        'users' => [
            'driver' => 'eloquent',
            'model'  => App\Models\Boilerplate\User::class,
            'table'  => 'users',
        ],
    ],

which is the model scaffholded (different from what the UsersDatatable class is loading). That's why I have this exception, I can fix this copying the UsersDatatable file in myapp/app/Datatables, but I suppose that if I call the scaffhold command this file should be automatically copied in there, agree with me?

sebastienheyd commented 2 years ago

Yes, you're right. Databables folder is not copied and it must be.

Ok, one more fix :)

sebastienheyd commented 2 years ago

Fixed in 7.11.4