Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cascading Select option is not working . #5851

Open
jesnagifto opened this issue Mar 19, 2024 · 4 comments
Open

Cascading Select option is not working . #5851

jesnagifto opened this issue Mar 19, 2024 · 4 comments

Comments

@jesnagifto
Copy link

jesnagifto commented Mar 19, 2024

  • Laravel Version:"^8.83"
  • PHP Version:"^8.0.2|^8.2.4"
  • Laravel-admin:"^1.8"

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
Copy link
Author

Screenshot 2024-03-19 123139

@jesnagifto
Copy link
Author

help me please?

@Ladel
Copy link
Contributor

Ladel commented Mar 22, 2024

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
Copy link

optiktr commented May 16, 2024

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');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants