z-song / laravel-admin

Build a full-featured administrative interface in ten minutes
https://laravel-admin.org
MIT License
11.1k stars 2.81k forks source link

Cascading Select option is not working . #5851

Open jesnagifto opened 3 months ago

jesnagifto commented 3 months ago

Description:

public function brands(Request $request) { $brand = $request->get('q'); $brandNames = Brand_category::where('category_id', $brand) ->join('brands', 'brand_category.brands_id', '=', 'brands.id') ->get(['brands_id', DB::raw('brand_name as text')]); log::info($brandNames);

return $brandNames;

}

Steps To Reproduce:

$form->select('catg_id', __('Category Name')) ->options(Category::all()->pluck('catg_name', 'id')) ->setWidth(4, 2) ->load('brand_id', '/admin/api/brands'); $form->select('brand_id', __('Brand Name')) ->setWidth(4, 2);

this code wise load the values we can not selecthem.

jesnagifto commented 3 months ago

Screenshot 2024-03-19 123139

jesnagifto commented 3 months ago

help me please?

Ladel commented 3 months ago

Maybe this will help

... ->get(['brands_id', DB::raw('brand_name as text')]); .. to ->get([DB::raw('brand_category.brands_id as id'), DB::raw('brand_name as text')]);

optiktr commented 1 month ago

For API...

public function brands(Request $request)
{
    $brand = $request->get('q');
    $brandNames = Brand_category::where('category_id', $brand)
        ->join('brands', 'brand_category.brands_id', '=', 'brands.id')
        ->get([DB::raw('brand_category.brands_id as id'), DB::raw('brand_name as text')]);
    log::info($brandNames);

    return $brandNames;
}

For Form...

$form->select('catg_id', __('Category Name'))
    ->options(Category::all()->pluck('catg_name', 'id'))
    ->ajax('/admin/api/brands');

OR

$form->select('catg_id', 'Select Category')->options(function ($id) {
        $category= Category::find($id);

        if ($category) {
            return [$category->id => $category->brand_name ];
        }
})
->ajax('/admin/api/brands');