在控制器中使用apend进行数据调用

时间:2018-11-27 05:25:26

标签: html laravel controller

嗨。我正在学习Laravel

我使用追加在选择选项中输入数据

这是我的附加代码

if($('.type').val()=="MAG") {
            $('.tools').empty();
           $('.tools').append('<?php echo $MAGRES ?>');


            $(".tools").prop('disabled', false);

            $('.level').empty();
            $('.level').append('<?php echo $mlevel ?>');
            $(".level").prop('disabled', false);


        }

        if($('.type').val()=="WAG") {
            $('.tools').empty();
            $('.tools').append('<?php echo $WAGRES ?>');


            $(".tools").prop('disabled', false);

            $('.level').empty();
            $('.level').append('<?php echo $flevel ?>');
            $(".level").prop('disabled', false);
        }

这是我的控制人

$openM =\App\eventcontroller::where('eventcontroller.eventID','=',$id)->where('type','MAG')->first();
$openF =\App\eventcontroller::where('eventcontroller.eventID','=',$id)->where('type','WAG')->first();

    $mlevel='<option value="">-- Choose Levels --</option>';
    $flevel='<option value="">-- Choose Levels --</option>';

    if($openM->OneO == 1 || $openM->OneA == 1 || $openM->OneB == 1 || $openM->OneC == 1 || $openM->OneD == 1){$mlevel=$mlevel.'<option value="Level 1">Level {{$event->onename}} </option>';}
    if($openM->TwoO == 1 || $openM->TwoA == 1 || $openM->TwoB == 1 || $openM->TwoC == 1 || $openM->TwoD == 1){$mlevel=$mlevel.'<option value="Level 2">Level {{$event->twoname}}</option>';}
    if($openM->ThreeO == 1 || $openM->ThreeA == 1 || $openM->ThreeB == 1 || $openM->ThreeC == 1 || $openM->ThreeD == 1){$mlevel=$mlevel.'<option value="Level 3">Level {{$event->threename}}</option>';}
    if($openM->FourO == 1 || $openM->FourA == 1 || $openM->FourB == 1 || $openM->FourC == 1 || $openM->FourD == 1){$mlevel=$mlevel.'<option value="Level 4">Level {{$event->fourname}}</option>';}
    if($openM->FiveO == 1 || $openM->FiveA == 1 || $openM->FiveB == 1 || $openM->FiveC == 1 || $openM->FiveD == 1){$mlevel=$mlevel.'<option value="Level 5">Level {{$event->fivename}}</option>';}
    if($openM->FigO == 1 || $openM->Fig1 == 1 ||$openM->Fig2 == 1){$mlevel=$mlevel.'<option value="FIG">FIG</option>';}

    if($openF->OneO == 1 || $openF->OneA == 1 || $openF->OneB == 1 || $openF->OneC == 1 || $openF->OneD == 1){$flevel=$flevel.'<option value="Level 1">Level {{$event->onename}}</option>';}
    if($openF->TwoO == 1 || $openF->TwoA == 1 || $openF->TwoB == 1 || $openF->TwoC == 1 || $openF->TwoD == 1){$flevel=$flevel.'<option value="Level 2">Level {{$event->twoname}}</option>';}
    if($openF->ThreeO == 1 || $openF->ThreeA == 1 || $openF->ThreeB == 1 || $openF->ThreeC == 1 || $openF->ThreeD == 1){$flevel=$flevel.'<option value="Level 3">Level {{$event->threename}}</option>';}
    if($openF->FourO == 1 || $openF->FourA == 1 || $openF->FourB == 1 || $openF->FourC == 1 || $openF->FourD == 1){$flevel=$flevel.'<option value="Level 4">Level {{$event->fourname}}</option>';}
    if($openF->FiveO == 1 || $openF->FiveA == 1 || $openF->FiveB == 1 || $openF->FiveC == 1 || $openF->FiveD == 1){$flevel=$flevel.'<option value="Level 5">Level {{$event->fivename}}</option>';}
    if($openF->FigO == 1 || $openF->Fig1 == 1 ||$openF->Fig2 == 1){$flevel=$flevel.'<option value="FIG">FIG</option>';}

显示选项没有问题

但其打印文字:

  

'{{$ event-> onename}}'不是$ event-> onename的数据

我希望它显示来自数据库的$event->onename数据。

有人可以帮助我吗?谢谢

1 个答案:

答案 0 :(得分:0)

因为您在控制器文件中使用Blade语法,所以它显示{{$event->onename}}而不是其实际值。

你可以喜欢

if($openM->OneO == 1 || $openM->OneA == 1 || $openM->OneB == 1 || $openM->OneC == 1 || $openM->OneD == 1){
    $mlevel= $mlevel."<option value=\"Level 1\">Level {$event->onename} </option>";
}

if($openM->OneO == 1 || $openM->OneA == 1 || $openM->OneB == 1 || $openM->OneC == 1 || $openM->OneD == 1){
    $mlevel = $mlevel.'<option value="Level 1">Level '.$event->onename.'</option>';
}