open-admin icon indicating copy to clipboard operation
open-admin copied to clipboard

API admin route for cascading select

Open DeltaServiceSoftware opened this issue 1 year ago • 9 comments

Hi, I installed open-admin with laravel 10 with the api tester but the api responds "The route api/user could not be found." if the request is api/user. But I enter the full project url, http://my_project.test/api/user, the api works. This does not allow me to create cascading select. Has anyone encountered this problem?

Thanks

DeltaServiceSoftware avatar Jan 05 '24 15:01 DeltaServiceSoftware

Hi there

No i don't have this issue

I create a "post" route and chain load('cascading_select_to_load') on the component

Example $router->post('my-route', 'yourController@myFunction');

<?php public function myFunction(Request $request){ if(!$request->get('query')){ return []; } $data = Model::where('extension_code',$request->get('query'))->pluck('column',column); $arr = []; foreach($data as $k => $v){ $arr[] = ['id'=>$k, 'text'=>$v]; } return $arr; } ?>

or however you would like to map the data,

control expects id and text behind a post route, it passes $request->input('query')

Thanks!

RCyrix avatar Jan 06 '24 16:01 RCyrix

image

Github is losing the formatting when surrounded in code quotes..... but anyway

RCyrix avatar Jan 06 '24 16:01 RCyrix

But please do check out the docs for a proper explanation on the cascading select

so long as you have a post route and provide the required feedback and have no javascript errors that would halt things in the browser it should work

RCyrix avatar Jan 06 '24 16:01 RCyrix

Hi there, thanks for help. Should the route be inserted in the \config\api.php or in app\Admin\routes.php file? If I enter the route in \config\api.php it is visible in Api-tester while if I enter app\Admin\routes.php it does not appear.

Thanks

DeltaServiceSoftware avatar Jan 08 '24 09:01 DeltaServiceSoftware

Hi there

When it makes its request it takes the url you pass it if i remember correctly, but i put it in App\Admin\routes file

RCyrix avatar Jan 08 '24 13:01 RCyrix

Hi there, if the issue is resolved, may i ask you to please close it?

Thanks!

RCyrix avatar Jan 13 '24 03:01 RCyrix

Hi there, thanks for help. Should the route be inserted in the \config\api.php or in app\Admin\routes.php file? If I enter the route in \config\api.php it is visible in Api-tester while if I enter app\Admin\routes.php it does not appear.

Thanks

My implementation is following the guide as below:

  1. Create new controller in app/Http/Controller/Api
  2. Add the route in route/api.php
  3. call the API like ->ajax('/api/nameOfYourFunction')

fadlisaad avatar Feb 08 '24 07:02 fadlisaad

i have an issue, json file with postman is correct, but i try to cast then the 'q' is null

Pblo16 avatar Mar 01 '24 06:03 Pblo16

i have an issue, json file with postman is correct, but i try to cast then the 'q' is null

It's turn out 'q' has been change with 'query'

fadlisaad avatar May 22 '24 06:05 fadlisaad