4

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.

massimo colella
  • 83
  • 1
  • 11
  • This is a laravel constraint. You cannot do it like that. Take a look at the manual https://laravel.com/docs/5.5/routing#route-group-prefixes – Indra Feb 27 '18 at 10:13
  • Thank you Indra. I guess your comment should be the answer, and not just a comment. – massimo colella Feb 28 '18 at 08:14

2 Answers2

6

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!

tabacitu
  • 6,047
  • 1
  • 23
  • 37
0

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'),
              .....
Seyacat
  • 21
  • 2