I got this error after I add type checklist
in setupCreateOperationFunction
. I want a checklist input fields in my form to insert data in my database. But its shows error:
call_user_func(): Argument #1 ($callback) must be a valid callback, array must have exactly two members.
Model File(JobPost.php)
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class JobPost extends Model
{
use \Backpack\CRUD\app\Models\Traits\CrudTrait;
use HasFactory;
protected $fillable = [
'title', 'description', 'job_type', 'work_mode', 'status'
];
protected $casts = [
'job_type' => 'array',
'work_mode' => 'array',
];
}
JobPostCrudController.php
namespace App\Http\Controllers\Admin;
use App\Http\Requests\JobPostRequest;
use Backpack\CRUD\app\Http\Controllers\CrudController;
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD;
/**
* Class JobPostCrudController
* @package App\Http\Controllers\Admin
* @property-read \Backpack\CRUD\app\Library\CrudPanel\CrudPanel $crud
*/
class JobPostCrudController 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;
/**
* Configure the CrudPanel object. Apply settings to all operations.
*
* @return void
*/
public function setup()
{
CRUD::setModel(\App\Models\JobPost::class);
CRUD::setRoute(config('backpack.base.route_prefix') . '/job-post');
CRUD::setEntityNameStrings('job post', 'Job Posts');
}
/**
* Define what happens when the List operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-list-entries
* @return void
*/
protected function setupListOperation()
{
/**
* Columns can be defined using the fluent syntax or array syntax:
* - CRUD::column('price')->type('number');
* - CRUD::addColumn(['name' => 'price', 'type' => 'number']);
*/
CRUD::addColumn([
'name' => 'title',
'label' => 'Job Title',
]);
CRUD::column('description');
CRUD::addColumn([
'name' => 'job_type',
'label' => 'Job Type',
'type' => 'text',
]);
CRUD::addColumn([
'name' => 'work_mode',
'label' => 'On-site/Remote',
'type' => 'text',
]);
CRUD::column('status');
}
/**
* Define what happens when the Create operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-create
* @return void
*/
protected function setupCreateOperation()
{
CRUD::setValidation(JobPostRequest::class);
/**
* Fields can be defined using the fluent syntax or array syntax:
* - CRUD::field('price')->type('number');
* - CRUD::addField(['name' => 'price', 'type' => 'number']));
*/
CRUD::addField([
'name' => 'title',
'label' => 'Job Title',
]);
CRUD::field('description');
CRUD::addField([
'name' => 'job_type',
'label' => 'Job Type',
'type' => 'checklist',
'options' => [
'Full Time' => 'Full Time',
'Part Time' => 'Part Time',
'Contract' => 'Contract'
],
'model' => "App\Models\JobPost",
'pivot' => false,
]);
CRUD::addField(['name' => 'status', 'type' => 'enum']);
}
/**
* Define what happens when the Update operation is loaded.
*
* @see https://backpackforlaravel.com/docs/crud-operation-update
* @return void
*/
protected function setupUpdateOperation()
{
$this->setupCreateOperation();
}