在Laravel的特定页面中显示表单

时间:2018-07-13 00:39:58

标签: php laravel

我有一个表单,并将其放在刀片模板中,我想在我的某些类别页面中显示它,而不是在所有页面中显示它。因此,我创建了一个表,该表获取类别ID,而另一列为ny,可以说是否显示具有此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

screenone

有什么主意吗?

1 个答案:

答案 0 :(得分:1)

您可以使用blade的@includeWhen指令。

类似这样的东西:

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

祝你好运!