z-song / laravel-admin

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

1.8 error on QuickSearch if use ->join #5654

Closed KomAuras closed 2 years ago

KomAuras commented 2 years ago

Description:

The search expression is not quoted if you use join in the model

Steps To Reproduce:

$grid = new Grid(new Products());
$grid->model()
    ->join('product_prov as pv', 'pv.id', '=', 'products.provider_id')
    ->leftJoin('article_descs as ad', 'ad.article_n', '=', 'products.article_n')
    ->leftJoin('product_pictures as pp', 'pp.product_id', '=', 'products.product_id')
    ->select('products.*', 'pv.prefix', 'pp.filename', 'ad.description as ext_desc');

Use QuickSearch for find any text, and get SQL code like:

SELECT count(*) AS AGGREGATE
FROM `products`
INNER JOIN `product_prov` AS `pv` ON `pv`.`id` = `products`.`provider_id` 
left JOIN `article_descs` AS `ad` ON `ad`.`article_n` = `products`.`article_n` 
left JOIN `product_pictures` AS `pp` ON `pp`.`product_id` = `products`.`product_id`
WHERE (`name` LIKE %1000115% OR `article_n` LIKE %1000115% OR `product_code` LIKE %1000115% OR `description` LIKE %1000115%)

An expression like this is created, without quotes

KomAuras commented 2 years ago

rewrite to with()