massimo colella
massimo colella

Reputation: 83

How to pass params in url to a backpack create form

I'm using backpack 3.3 on a laravel 5.5 installation. I want to prefill two create form fields with two URL passed values. Say you create a basic backpack crud, named Image. Normally you can go to domain/admin/image/create to view and fill in the form.

But if I add one or two params in the url, I get a 404. I guess I should manage the routes file (admin.php) I tried this way:

Route::group(['prefix' => 'image/{k}/{cid}'], function()
 {
   CRUD::resource('image', 'ImageCrudController');
 });

but still get a 404. Any suggestions? Thanks in advance.

Upvotes: 4

Views: 2788

Answers (2)

Seyacat
Seyacat

Reputation: 31

it works for me easier

http://127.0.0.1:8000/admin/resultado/create?competencia=2

$this->crud->modifyField("competencia_id",[
              'label' => "Competencia",
              "default"=>$this->crud->request->query->get('competencia'),
              .....

Upvotes: 0

tabacitu
tabacitu

Reputation: 6193

Almost all field types have a default option. So when you define them, you can specify a default. And you can always pass a GET parameter for that default. So you can have something like this in your EntityCrudController:

$this->crud->addField[ // Text
    'name' => 'title',
    'label' => "Title",
    'type' => 'text',
    'default'    => \Request::has('title')?\Request::has('title'):false, // default value
]);

You'd then be able to send you users to yourapp/admin/entity/create?title=your+default+value and have that default value show up in the field.

Hope it helps. Cheers!

Upvotes: 6

Related Questions