Closed mobi35 closed 11 months ago
Hello there! Thanks for opening your first issue on this repo!
Just a heads-up: Here at Backpack we use Github Issues only for tracking bugs. Talk about new features is also acceptable. This helps a lot in keeping our focus on improving Backpack. If you issue is not a bug/feature, please help us out by closing the issue yourself and posting in the appropriate medium (see below). If you're not sure where it fits, it's ok, a community member will probably reply to help you with that.
Backpack communication mediums:
backpack-for-laravel
tag;Please keep in mind Backpack offers no official / paid support. Whatever help you receive here, on Gitter, Slack or Stackoverflow is thanks to our awesome awesome community members, who give up some of their time to help their peers. If you want to join our community, just start pitching in. We take pride in being a welcoming bunch.
Thank you!
-- Justin Case The Backpack Robot
Hello @mobi35
Could you elaborate the question a little more, from what I understand you want to change the model that the package uses, could you show me the code and the versions that you are using
php artisan backpack:version
when you made the changes, did you clear the system cache?
php artisan optimize:clear
php artisan config:cache
Cheers
v10.24.0@bcebd0a4c015d5c38aeec299d355a42451dd3726
backpack/crud: 5.6.1 backpack/devtools: 1.3.5 backpack/editable-columns: 2.1.5 backpack/filemanager: 2.0.1 backpack/generators: v3.3.17 backpack/permissionmanager: 6.0.17 backpack/pro: 1.6.6
I cannot create or edit in users crud
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.users' doesn't exist, but the current model in users crud is admin, so I'm expecting it to use admins instead of users..
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb.users' doesn't exist is throwing where the correct table is 'mydb.admins'. It's kinda weird cause the list of data in users crud is the data from admins table, not sure why it's still searching for users table. I already cleared the cache.
Hello.
Let's check step by step.
Your config file is published and accessible in config/backpack/permissionmanager.php
'models' => [
'user' => \App\Models\Admin::class,
'permission' => Backpack\PermissionManager\app\Models\Permission::class,
'role' => Backpack\PermissionManager\app\Models\Role::class,
],
Your model has set correctly table name, like:
protected $table = 'admins';
Cheers.
'models' => [
'user' => config('backpack.base.user_model_fqn', \App\Models\Admin::class),
'permission' => Backpack\PermissionManager\app\Models\Permission::class,
'role' => Backpack\PermissionManager\app\Models\Role::class,
],
config ('backpack.base.user_model_fqn') is already \App\Models\Admin when I dd it, I even changed the fallback to Admin too. It's just throwing an error when Im creating and updating, The table is populating correct list from the Admin model.
Here's the structure of my admins table
Hello @mobi35 i make a try on my side and everything is working correctly.
config/backpack/base.php
'user_model_fqn' => '\App\Models\Admin',
app/Models/Admin.php
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;
use Illuminate\Notifications\Notifiable;
use Backpack\CRUD\app\Models\Traits\CrudTrait;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Admin extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
use CrudTrait;
use HasRoles;
protected $table = 'admins';
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
Im able to create, update or delete any instance of "admins" table.
### PHP VERSION:
PHP 8.2.11 (cli) (built: Oct 6 2023 09:46:55) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.11, Copyright (c) Zend Technologies
with Zend OPcache v8.2.11, Copyright (c), by Zend Technologies
### LARAVEL VERSION:
10.26.2.0
### BACKPACK PACKAGE VERSIONS:
backpack/basset: 1.2.1
backpack/crud: 6.2.3
backpack/generators: v4.0.2
backpack/permissionmanager: 7.0.1
backpack/pro: 2.0.14
backpack/theme-coreuiv2: 1.2.1
backpack/theme-coreuiv4: 1.1.1
backpack/theme-tabler: 1.1.1
Cheers.
I fixed the issue by putting
'users' => 'admins,
in table_names at permission.php.
//UserCrudController
public function update () {
$this->crud->setRequest($this->crud->validateRequest()); // error is happening in this line.
}
Thank you so much for answering my question.
in permissionsmanager.php, I already set the model to Admin::class, but it's still looking for User::class. What could be the reason? I'm using backpack 5.5. I can see the data from Admin::class in the list, but I cannot edit or create a new one.