php - 在 laravel 的特定页面中显示表单
问题描述
我有一个表格,我把它放在刀片模板中,我想在我的一些类别页面中显示它,而不是全部。因此,我创建了一个表格,该表格获取类别 ID 和另一列,n
或者y
让我说是否在具有此 ID 的类别中显示该表格。
问题
问题是,无论我选择什么n
或y
我的表单都加载到我的所有类别页面中。
代码
Category model
public function categoryfinderactivess(){
return $this->belongsToMany(CategoryFinderActive::class, 'category_finder_actives', 'category_id', 'active');
}
CategoryFinderActive model
class CategoryFinderActive extends Model
{
public $timestamps = false;
protected $fillable = [
'category_id', 'active',
];
public function category(){
return $this->belongsTo(Category::class, 'category_id');
}
}
controller
$finderactive = CategoryFinderActive::where('category_id', $category->id)->where('active', '=', 'y')->get();
blade
@if($finderactive)
@include('front.partials.indexPage.catfinder')
@endif
screenshot
任何的想法?
解决方案
您可以使用刀片的 @includeWhen 指令。
像这样的东西:
@includeWhen( ($finderactive && (count($finderactive) > 0) ), 'front.partials.indexPage.catfinder')
祝你好运!!!
推荐阅读
- javascript - Channel_not_found:authed_user 无法通过 Slack API 向频道发布消息
- java - 使用 Eclipse 警告的 PMD 规则集
- google-sheets - 让用户覆盖由 Google 表单生成的预填电子表格复选框
- swift - CoreData Int32 标量问题
- mysql - 带有条件的 MYSQL GROUP BY 2 字段
- c# - Html.BeginForm 仅传递我的第一个文件夹路径的值
- javascript - 谷歌图表没有更新状态变化甚至 forceUpdate
- javascript - 为什么clearInterval不会立即在heroku中停止
- html - DIV 内的 HTML 水平滚动,无需页面滚动
- java - Java如何获取包括异常类型在内的前N行异常?