No query results for model [App\Models\Customer] backpack

887 Views Asked by At

I am using laravel backpack package and while edit and delete or preview operation I am getting the below error.

No query results for model [App\Models\Customer] record id

I have included the model. What am I am missing?

And one more thing the record id which is showing in the error it is not present in the table, But the backpack list interface is showing. why? And this table is a master. Any CRUD operation will happen only for its own tbl only not affecting any other tbl. Below is controller

 <?PHP
   namespace App\Http\Controllers\Admin;
   use App\Models\Customer;
   use Illuminate\Support\Facades\DB;
   use App\Http\Requests\CustomerRequest;
   use Backpack\CRUD\app\Http\Controllers\CrudController;
   use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
   use Carbon\Carbon;

   class CustomerCrudController extends CrudController
  {
   use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
   use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation 
   {store as traitstore;}
   use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation 
   {update as traitupdate;}
   use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation 
   {destroy as traitDestroy;}
   use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;


public function setup()
{
    //$this->crud->enableExportButtons();
    $this->crud->setModel('App\Models\Customer');
    $this->crud->setRoute(config('backpack.base.route_prefix') . '/customer');
    $this->crud->setEntityNameStrings('customer', 'customers');     
}

protected function setupListOperation()
{
    // TODO: remove setFromDb() and manually define Columns, maybe Filters
    //$this->crud->setFromDb();
   
    $this->crud->setColumns([
        [
            'name'  => 'company_name',
            'label' => 'Company',
            'type'  => 'text',
        ],
        [
            'name'  => 'company_address1',
            'label' => 'Primary Add',
            'type'  => 'text',
        ],
        [
            'name'  => 'primary_contact',
            'label' => 'Primary Cont',
            'type'  => 'text',
        ],
        [
            'name'  => 'company_city',
            'label' => 'city',
            'type'  => 'text',
        ]
    ]);
   

    }
}

Model is

<?PHP 
   
namespace App\Models;
use Backpack\CRUD\app\Models\Traits\CrudTrait;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Customer extends Model
{
    use CrudTrait, SoftDeletes;

    protected $table = 'customers';
    protected $primaryKey = "cust_id";

    protected $fillable = [
        'company_name',
        'company_address1',
        'company_address2',
        'company_city',
        'company_zip',
        'company_country',
        'company_state',
        'company_vat',
        'company_id',
        'primary_contact',
        'technical_contact',
        'financial_contact',
        'cust_def_time_zone',
        'created_at',
        'updated_at',
        'deleted_at' ];
}
1

There are 1 best solutions below

0
On

edit setupShowOperation function in CustomerCrudController add this

Customer::withTrashed()->find(\request()->id);