[英]Conditional BREAD in Laravel / Voyager
Is there a way to apply certain conditions to the list of records displayed by Voyager's BREAD?有没有办法对 Voyager's BREAD 显示的记录列表应用某些条件? For example, only display records where a certain column is blank (ie
WHERE 'col_name' IS NULL
)?例如,只显示某一
WHERE 'col_name' IS NULL
空的记录(即WHERE 'col_name' IS NULL
)?
UPDATE (17/12/18):更新 (17/12/18):
You can override the controller and add the where clause.您可以覆盖控制器并添加 where 子句。 For example, if you need to override "Posts" list, then you should:
例如,如果您需要覆盖“帖子”列表,那么您应该:
php artisan make:controller PostController
php artisan make:controller PostController
class PostController extends \\TCG\\Voyager\\Http\\Controllers\\VoyagerBaseController
class PostController extends \\TCG\\Voyager\\Http\\Controllers\\VoyagerBaseController
use TCG\\Voyager\\Facades\\Voyager;
use TCG\\Voyager\\Facades\\Voyager;
\\vendor\\tcg\\Voyager\\Http\\Controllers\\VoyagerBaseController
\\vendor\\tcg\\Voyager\\Http\\Controllers\\VoyagerBaseController
找到它 $dataType = Voyager::model('DataType') ->where('slug', '=', $slug) ->where('col_name', '=', NULL) ->first();
You can also set $orderBy = 'col_name'
and $sortOrder = 'asc'/'desc'
custom values in the same function.您还可以在同一函数中设置
$orderBy = 'col_name'
和$sortOrder = 'asc'/'desc'
自定义值。 Here Voyager's docs. 这里是航海者的文档。
OLD:老的:
Yes, there is.就在这里。 You need to edit the view and apply a condition filter.
您需要编辑视图并应用条件过滤器。 Here is explained how to override views (and controllers if you want to filter it before sending the data to the view).
这里解释了如何覆盖视图(如果你想在将数据发送到视图之前过滤它,还有控制器)。
Just define a Scope in your model:只需在您的模型中定义一个范围:
public function scopeMyScope($query)
{
return $query->where('col_name', null);
}
then go to Bread Form and select it form Scope drop down :)然后转到 Bread Form 并从 Scope 下拉菜单中选择它 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.