Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Blade@if-Laravel中调用变量_Php_Laravel_Laravel Blade - Fatal编程技术网

Php 如何在Blade@if-Laravel中调用变量

Php 如何在Blade@if-Laravel中调用变量,php,laravel,laravel-blade,Php,Laravel,Laravel Blade,我正在从事这个项目,在这个项目中,我可以在测试中成功地实现以下代码的结果: $Counts = sentcount::find(Auth::user()->id)->TotalCount; $Counts2 = sentcount::find(Auth::user()->id)->SentCount; $Remaining = $Counts - $Counts2; if ($Remaining === 0){ echo "You

我正在从事这个项目,在这个项目中,我可以在测试中成功地实现以下代码的结果:

$Counts = sentcount::find(Auth::user()->id)->TotalCount;
    $Counts2 = sentcount::find(Auth::user()->id)->SentCount;
    $Remaining = $Counts - $Counts2;
    if ($Remaining === 0){
        echo "You have reached your limits";
    } else {
        echo "You have" .$Remaining. " Remaining";
    }
但我想用剩下的$3作为我的刀片,比如: 我是blade的新手,我知道我可以将剩余的数据保存到我的数据库中,然后像
App\sentcount::find(\illumb\Support\Facades\Auth::user()->id)->剩余===0

调用
@if
&
@else

我的刀片代码:

@if ( App\sentcount::find(\Illuminate\Support\Facades\Auth::user()->id)->TotalCount > 0 )
                        <div class="text" style="max-width: 80%; padding-left: 3%; padding-top: 2%">
                        Usage:<br>
                        <h3 class="Sent" style="color: #1d68a7">Sent: {{  \App\sentcount::find(Auth::user()->id)->SentCount }}</h3>
                        <h3 class="Total" style="color: #2a9055">Remaining: {{  $Remaining }} </h3>
                        <div class="progress">
                            <div class="progress-bar" role="progressbar" style="width: {{  $Percent }}%;" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">{{  $Percent }}%</div>
                        </div><br>
                        </div>
                        <hr>
                    @elseif( $Remaining === 0 )
                        You have reached your limits
                    @else
                        <div class="alert alert-dark" role="alert">
                            <h4 class="alert-heading">Oops!! You don't have any active subscription.</h4>
                            You can purchase a plan here <a href="Plans" class="alert-link">"Plans"</a>. <br>Open a support ticket for any help regarding purchases!.
                            <hr>
                        </div>
                    @endif

假设这是你的控制器

public function show(User $user){

           $remaining = 'your value';

            return view('folder.bladefile', compact('remaining'));//so we are passing the variable to our blade file

    }
在刀片文件中,您可以执行以下操作

@if($remaining === 4)

//do this
//sometimes you might have to do count($remaining) if $remaining returns an array

@elseif($remaining < 1)

//you have reached your limit

@else

//do something else if none of the conditions are met

@endif
@if($剩余===4)
//这样做
//有时,如果$remaining返回一个数组,您可能需要执行count($remaining)
@elseif(剩余<1美元)
//你已经达到极限了
@否则
//如果不满足任何条件,请执行其他操作
@恩迪夫

假设这是您的控制器

public function show(User $user){

           $remaining = 'your value';

            return view('folder.bladefile', compact('remaining'));//so we are passing the variable to our blade file

    }
在刀片文件中,您可以执行以下操作

@if($remaining === 4)

//do this
//sometimes you might have to do count($remaining) if $remaining returns an array

@elseif($remaining < 1)

//you have reached your limit

@else

//do something else if none of the conditions are met

@endif
@if($剩余===4)
//这样做
//有时,如果$remaining返回一个数组,您可能需要执行count($remaining)
@elseif(剩余<1美元)
//你已经达到极限了
@否则
//如果不满足任何条件,请执行其他操作
@恩迪夫

如果从控制器传递,您可以在刀片服务器中使用剩余的$。为什么代码中有4个(控制器?)而视图中有0个?@codervine我尝试过这个方法如果($restain==0)您已经达到了极限!但似乎它不工作,因为我的代码被发送到其他人,而没有显示elseif@Saly3301我只是用4检查它,这样我可以检查它在条件下的工作情况,可以将其更改为0,但这并不重要,因为它只是一个测试代码。如果从控制器传递,您可以在刀片中使用剩余的$。为什么代码中有4(控制器?)看到0了吗?@codervine我试过这个方法如果($剩余===0)你已经达到极限了!但似乎它不工作,因为我的代码被发送到其他人,而没有显示elseif@Saly3301我只是用4检查它,这样我可以检查它在条件下的工作情况。可以将它更改为0,但这并不重要,因为它只是一个测试代码。使用blade和controller更新,我需要与我的elseif一起工作。如果您可以在我的代码中看到始终欢迎更新有了刀片和控制器,我需要和我的同事一起工作如果你能在我的代码中看到总是欢迎兄弟