首页 > 解决方案 > 在 laravel 的特定页面中显示表单

问题描述

我有一个表格,我把它放在刀片模板中,我想在我的一些类别页面中显示它,而不是全部。因此,我创建了一个表格,该表格获取类别 ID 和另一列,n或者y让我说是否在具有此 ID 的类别中显示该表格。

问题

问题是,无论我选择什么ny我的表单都加载到我的所有类别页面中。

代码

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

屏风

任何的想法?

标签: phplaravel

解决方案


您可以使用刀片的 @includeWhen 指令。

像这样的东西:

@includeWhen( ($finderactive && (count($finderactive) > 0) ), 'front.partials.indexPage.catfinder')

祝你好运!!!


推荐阅读