如何在blade.php中的if语句中分配变量

时间:2019-04-16 17:19:18

标签: php laravel-5 laravel-blade laraadmin

CREATE PROC [dbo].[spsearchp]
@SearchBy   varchar(50),
@SearchVal  varchar(50)
AS 
BEGIN
IF @SearchBy = 'P_name'
BEGIN
select * from Products LEFT JOIN Category ON Products.PCid= Category.cid where P_name like '%' + @SearchVal + '%'
END
ELSE IF @SearchBy = 'P_active'
BEGIN
select * from Products LEFT JOIN Category ON Products.PCid= Category.cid WHERE P_active like '%' + @SearchVal + '%'
END
ELSE
BEGIN
select * from Products LEFT JOIN Category ON Products.PCid= Category.cid
END
END

如果if陈述为true,我想将history_car_positions分配给$ module名称如何在刀片中做到这一点

3 个答案:

答案 0 :(得分:1)

我首先要注意您的语法不正确-您正在比较(==),而不是在分配(=)。

但是,作为解释器的Blade拥有its own control structure的原始PHP。

但是,如果只是将此变量传递给itemCount,则可能要在视图中而不是直接在模板中求值并赋值。维护起来会更加干净。

答案 1 :(得分:0)

您可以尝试使用php指令laravel docs

@if ($module->name === "h_car_positions")
   @php
      $module_name = "history_car_positions"; // use = instead of ==
   @endphp
@endif

答案 2 :(得分:0)

使用php标记

@if ($module->name === "h_car_positions")  <?php $module_name = "history_car_positions"; ?> @endif