open-admin-org / open-admin

open-admin forked from z-song/laravel-ladmin. Removing jquery, now based on Bootstrap5, vanilla JS
https://open-admin.org
MIT License
254 stars 73 forks source link

API admin route for cascading select #132

Open DeltaServiceSoftware opened 9 months ago

DeltaServiceSoftware commented 9 months ago

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

RCyrix commented 9 months ago

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 commented 9 months ago

image

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

RCyrix commented 9 months ago

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

DeltaServiceSoftware commented 9 months ago

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

RCyrix commented 9 months ago

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 commented 9 months ago

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

Thanks!

fadlisaad commented 8 months ago

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')
Pblo16 commented 7 months ago

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

fadlisaad commented 5 months ago

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'