open-admin
open-admin copied to clipboard
API admin route for cascading select
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
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!
Github is losing the formatting when surrounded in code quotes..... but anyway
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
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
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
Hi there, if the issue is resolved, may i ask you to please close it?
Thanks!
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:
- Create new controller in app/Http/Controller/Api
- Add the route in route/api.php
- call the API like ->ajax('/api/nameOfYourFunction')
i have an issue, json file with postman is correct, but i try to cast then the 'q' is null
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'