小编Hưn*_*ịnh的帖子

Laravel:如何在刀片模板中获取直接配置值?

我想在刀片中获取配置值。

config/define.php
<?php
return [
    'show' => array(1 => 'Show',0 => 'Hide' ),
];
Run Code Online (Sandbox Code Playgroud)

我找到了一个代码

{{ Config::get('define.show') }}
Run Code Online (Sandbox Code Playgroud)

但我想使用:

{{ $showarray = Config::get('define.show') }}

@foreach ($master as $pt)
{{ $showarray[$pt->show_flag] }}
@endforeach
Run Code Online (Sandbox Code Playgroud)

但它不起作用。请帮帮我!

php laravel laravel-5 laravel-blade

5
推荐指数
1
解决办法
9677
查看次数

Laravel Eloquent:在 where 添加过滤器(条件查询的 if-else)?

我有这个代码:

$result = DB::table('product as p')
      ->join('master as cl', 'p.color', '=', 'cl.name')
      ->join('master as brand', 'p.brand', '=', 'brand.name')
      ->where('p.brand', $brandname)
      ->whereRaw("p.del_flag = 0  and cl.is_active = 1 and brand.is_active = 1 and p.product_type = 1")
      ->select('p.name')
      ->groupBy('p.name')
      ->orderBy('p.name')
      ->take(3)
      ->get();
Run Code Online (Sandbox Code Playgroud)

我需要添加过滤器:

if(isset($_POST['brand'])) {
    ->where('p.brand', $_POST['brand'])
}
if(isset($_POST['color'])) {
    ->where('p.color', $_POST['color'])
}
if(isset($_POST['product_type'])) {
    ->where('p.product_type', $_POST['product_type'])
}
Run Code Online (Sandbox Code Playgroud)

我看过很多关于 Laravel 中多个Where 的帖子,但没有一篇讨论那些特殊的Where。

如何在查询中添加过滤器?

laravel eloquent laravel-5

1
推荐指数
1
解决办法
7774
查看次数

标签 统计

laravel ×2

laravel-5 ×2

eloquent ×1

laravel-blade ×1

php ×1