'Backpack for laravel -> I can't get + Add Inline Create

I want to use the Inline Create functionality of Backpack for Laravel but the button "Add +" doesn't shows up.

I have a 1 to n relationship

The primary model is Inscription and the secondary is InscriptionProduct

This is my code:

Models\Inscription

...
class Inscription extends Model
{
 
    public function product() {
        return $this->hasMany('App\Models\InscriptionProduct');
    }
...

Models\InscriptionProduct

...
class InscriptionProduct extends Model
{

    public function inscription()
    {
        return $this->belongsTo(Inscription::class);
    }
...

Http\Controllers\Admin\InscriptionProductCrudController

...
class InscriptionProductCrudController 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;

    use \Backpack\CRUD\app\Http\Controllers\Operations\InlineCreateOperation;
...

Http\Controllers\Admin\InscriptionCrudController

...
class InscriptionCrudController extends CrudController
{

    protected function setupCreateOperation()
    {
      ...
        $this->crud->addField([
            'type' => "relationship",
            'name' => 'product',
            'ajax' => true,
            'inline_create' => true,
            // 'data_source' => backpack_url('/admin/inscription-product/inline/create'),
            // 'data_source' => backpack_url('inscription/fetch/inscription-product'),
            // 'inline_create' => [ 'entity' => 'inscriptionproduct' ]
            // These 3 commented lines are alternatives also tried with no results
        ]);
...

The Relationship is well constructed because I can see the Products I have created via the CRUD of InscriptionProduct

The Relationship is well constructed because I can see the Products i have created via the CRUD of InscriptionProduct

What am I missing?



Solution 1:[1]

I solve it to, in your main CrudController, you should call the InLineCreate just below CreateOperation.

use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation { store as traitStore; }
use \Backpack\CRUD\app\Http\Controllers\Operations\InlineCreateOperation { store as traitStore; }

Also in my secondary CrudController I had to create a fetch function, something I did

  protected function fetchFeatures()
    {
        return $this->fetch([
            'model' => \App\Models\Features::class, // required
            'searchable_attributes' => ['name', 'slug'],
            'query' => function($model) {
                return $model;
            } // to filter the results that are returned
        ]);
        return $this->traitFetch();
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dharman