Когда я загружаю страницу, она выдает мне сообщение об ошибке и требует перезагрузки.
Однако, когда я добавляю данные в базу данных, она работает правильно.
Итак, в основном, моя функция списка не работает и Я не знаю почему.
Я проверил на опечатки, это не может быть чем-то вроде обновления, потому что все мои другие CRUD работают нормально с тем же методом.
Контроллер:
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\ProjectRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
/**
* Class ProjectCrudController
* @package App\Http\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class ProjectCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
public function setup()
{
$this->crud->setModel('App\Models\Project');
$this->crud->setRoute(config('backpack.base.route_prefix') . '/project');
$this->crud->setEntityNameStrings('project', 'projects');
}
protected function setupListOperation()
{
$this->crud->setColumns([
'name' => 'status',
'type' => 'text',
'label' => 'Status'
]);
$this->crud->setColumns([
'name' => 'topic',
'type' => 'text',
'label' => 'Topic'
]);
$this->crud->setColumns([
'name' => 'leader',
'type' => 'text',
'label' => 'Leader'
]);
$this->crud->setColumns([
'name' => 'email',
'type' => 'text',
'label' => 'Name'
]);
$this->crud->setColumns([
'name' => 'tags',
'type' => 'text',
'label' => 'Tags'
]);
}
protected function setupCreateOperation()
{
$this->crud->setValidation(ProjectRequest::class);
$this->crud->addField([
'name' => 'status',
'type' => 'text',
'label' => 'Status'
]);
$this->crud->addField([
'name' => 'topic',
'type' => 'text',
'label' => 'Topic'
]);
$this->crud->addField([
'name' => 'leader',
'type' => 'text',
'label' => 'Leader'
]);
$this->crud->addField([
'name' => 'email',
'type' => 'text',
'label' => 'Name'
]);
$this->crud->addField([
'name' => 'tags',
'type' => 'text',
'label' => 'Tags'
]);
}
protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}
public function store()
{
$this->crud->hasAccessOrFail('create');
// execute the FormRequest authorization and validation, if one is required
$request = $this->crud->validateRequest();
// insert item in the db
$item = $this->crud->create($this->crud->getStrippedSaveRequest());
$this->data['entry'] = $this->crud->entry = $item;
// show a success message
\Alert::success(trans('backpack::crud.insert_success'))->flash();
// save the redirect choice for next time
$this->crud->setSaveAction();
return $this->crud->performSaveAction($item->getKey());
}
}
Модель:
<?php
namespace App\Models;
use Backpack\CRUD\app\Models\Traits\CrudTrait;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
use CrudTrait;
/*
|--------------------------------------------------------------------------
| GLOBAL VARIABLES
|--------------------------------------------------------------------------
*/
protected $table = 'projects';
// protected $primaryKey = 'id';
// public $timestamps = false;
protected $guarded = ['project_id'];
protected $fillable = ['topic', 'status', 'leader', 'email', 'tags'];
// protected $fillable = [];
// protected $hidden = [];
// protected $dates = [];
/*
|--------------------------------------------------------------------------
| FUNCTIONS
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| RELATIONS
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| SCOPES
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| ACCESSORS
|--------------------------------------------------------------------------
*/
/*
|--------------------------------------------------------------------------
| MUTATORS
|--------------------------------------------------------------------------
*/
}
Запрос:
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
use Illuminate\Foundation\Http\FormRequest;
class ProjectRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
// only allow updates if the user is logged in
return backpack_auth()->check();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'topic' => 'required|min:5|max:255',
'status' => '',
'leader' => 'required|min:5|max:255',
'email' => 'required|min:5|max:255',
'tags' => 'required|min:5|max:255'
];
}
/**
* Get the validation attributes that apply to the request.
*
* @return array
*/
public function attributes()
{
return [
//
];
}
/**
* Get the validation messages that apply to the request.
*
* @return array
*/
public function messages()
{
return [
//
];
}
}