简体   繁体   English

Laravel / Voyager 中的条件面包

[英]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:例如,如果您需要覆盖“帖子”列表,那么您应该:

  1. Make a custom PostController: php artisan make:controller PostController制作一个自定义的 PostController: php artisan make:controller PostController
  2. Extend it from Voyager BREAD controller: class PostController extends \\TCG\\Voyager\\Http\\Controllers\\VoyagerBaseController从 Voyager BREAD 控制器扩展它: class PostController extends \\TCG\\Voyager\\Http\\Controllers\\VoyagerBaseController
  3. Import Voyager's Facade: use TCG\\Voyager\\Facades\\Voyager;导入 Voyager 的 Facade: use TCG\\Voyager\\Facades\\Voyager;
  4. Copy the whole index function from VoyagerBaseController.从 VoyagerBaseController 复制整个索引函数。 You can find it in \\vendor\\tcg\\Voyager\\Http\\Controllers\\VoyagerBaseController您可以在\\vendor\\tcg\\Voyager\\Http\\Controllers\\VoyagerBaseController找到它
  5. Override it to add any logic or filter you need, for example:覆盖它以添加您需要的任何逻辑或过滤器,例如:

$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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM