Reputation: 573
Trying to use inline_create i can create in modal but i can't select i get error
Method not allowed The POST method is not supported for this route. Supported methods: GET, HEAD.
URL is : http://127.0.0.1:8000/admin/question/fetch/tags
Field
$this->crud->addField(
[
'label' => "Les mote clé",
'minimum_input_length' => 0,
'type' => 'relationship',
'name' => 'tags', // the method that defines the relationship in your Model
'ajax' => true,
// 'method' => 'GET',
'minimum_input_length' => 0,
'attribute' => 'name', // foreign key attribute that is shown to user
'inline_create' => [ // specify the entity in singular
'entity' => 'tag', // the entity in singular
'force_select' => true, // should the inline-created entry be immediately selected?
'modal_class' => 'modal-dialog modal-md', // use modal-sm, modal-lg to change width
'modal_route' => route('tag-inline-create'), // InlineCreate::getInlineCreateModal()
'create_route' => route('tag-inline-create-save'), // InlineCreate::storeInlineCreate()
]
]
);
Question modal
// tags
public function tags()
{
return $this->belongsToMany(Tag::class, 'question_tags', 'question_id', 'tag_id');
}
Upvotes: 1
Views: 425
Reputation: 573
I finally found the problem.
I needed to define the ajax route to work with the field, either creating my own endpoin, or using FetchOperation
https://backpackforlaravel.com/docs/5.x/crud-operation-fetch#about-1.
In QuestionCrudController
:
use \Backpack\CRUD\app\Http\Controllers\Operations\FetchOperation;
...
public function fetchTags()
{
return $this->fetch(Tag::class);
}
Upvotes: 2