I installed backpack on the latest version of Laravel 6.
Upon running this command as a test:
php artisan make:migration:schema create_posts_table --schema="user_id:unsignedInteger:foreign,
name:string, slug:string, description:text, keywords:string:nullable"
The command created a Post model in Models/Post
I would like to see the names of the users from the "user" table in my "post" CRUD.
First question: I generate my CRUD with:
php artisan backpack:crud post
I see the CRUD, at the top of the CRUD I would like to pass the users name from the User table in the select dropdown.
I tried this:
protected function setupCreateOperation()
{
$this->crud->setValidation(PostRequest::class);
// TODO: remove setFromDb() and manually define Fields
//$this->crud->setFromDb();
$this->crud->setColumnDetails([
'label' => 'User', // Table column heading
'type' => 'select',
'name' => 'user_id', // the column that contains the ID of that connected entity;
'entity' => 'backpackuser', // the method that defines the relationship in your Model
'attribute' => 'name', // foreign key attribute that is shown to user
'model' => 'App\Models\backpackuser' // foreign key model
]);
}
But I am getting the error:
Symfony\Component\Debug\Exception\FatalThrowableError
Too few arguments to function Backpack\CRUD\app\Library\CrudPanel\CrudPanel::setColumnDetails(), 1
passed in C:\laragon\www\backpack\app\Http\Controllers\Admin\PostCrudController.php on line 41 and
exactly 2 expected
My problem "I think" is related to the "'entity' => 'backpackuser',"
From what I understand I need to add the relation method here but what I don't get is that Backpack did not create it when running the first command, is this normal?
Also, which model shall I user to pass the user details into a select field? App/User or App/Models/BackpackUser ?
Thank you.