Laravel,将新功能传递给刀片 [英] Laravel, passing new function to blade

查看:75
本文介绍了Laravel,将新功能传递给刀片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作类文件,控制器和视图,它们显示不同的数据样本,但是我当前正在添加一个新函数,该函数从数据库中获取数据,将其传递给控制器​​并进行定义,然后将其传递给刀片/视图.

I have a working class file, controller and view that show different samples of data, but I'm currently adding a new function which grabs data from the database, passing that to the controller and defining it, then passing it to the blade/view.

我所做的与其他功能没有什么不同,但是数据没有显示在刀片​​中.占位符在网页上的间距适当,但是没有显示数据.该查询正在获取结果,并且该函数正在传递给刀片,因为foreach正在创建其他行.我想我对刀片中的变量使用了不正确的语法,这就是为什么我的数据没有真正显示出来的原因.

I'm not really doing anything differently than the other functions but the data is not showing in my blade. The placeholder is spaced appropriately on the webpage but the data doesn't show up. The query is getting results and the function is passing to the blade because the foreach is creating additional rows. I'm thinking I'm using improper syntax for the variables in my blade which is why my data isn't actually showing.

在此感谢任何帮助:

EMPLOYEE.php

class employeeCalls
{
    public function __construct()
    {
        $this->yyyy = date('Y');
        $this->pyyy = $this->yyyy - 1;
        $this->from = "{$this->pyyy}-01-01";
        $this->through = $this->pyyy . '-' . date('m-d');
        $this->fullYear = "{$this->pyyy}-12-31";
        $this->newFrom = "{$this->yyyy}-01-01";
        $this->newThrough = date('Y-m-d'); 
    }

public function sample($employee)
    {
        $employee = (int) $employee;
        $from = $this->from;
        $through = $this->through;
        $newFrom = $this->newFrom;
        $newThrough = $this->newThrough;
        $FullYear = $this->fullYear;

        $sql = "
                select employee, 'PRIOR' as Range, count(*) as count
                from empCalls
                where employee = {$employee}
                AND fordate between '{$from}' and '{$through}'
                group by employee
            union all
                select employee, 'CURRENT' as Range, count(*) as count
                from empCalls
                where employee = {$employee}
                AND fordate between '{$newFrom}' and '{$newThrough}'
                group by employee
            union ALL
                select employee, 'FULL' as Range, count(*) as count
                from empCalls
                where employee = {$employee}
                AND fordate between '{$from}' and '{$FullYear}'
                group by employee
        ";

        return Connection::runQuery($sql);
    }
}

EmployeeController.php

    $employeeCalls = new employeeCalls();

    $samples = $employeeCalls->sample($this->slsno);

    return view('Employee.index')
            ->with('slsno', $this->slsno)
            ->with('samples', $samples);
    }

blade.php

<div class="md-card-content">
    @foreach($samples as $sample)
            <div class="uk-float-right uk-margin-small-right"><span class="uk-text-medium uk-text-center">{{ $sample['PRIOR'] }}</span></div>
            <span class="uk-text-muted uk-text-medium">2017 YTD</span>
            <div class="clearfix"></div>
            <div class="clearfix"></div>
            <hr />
            <div class="uk-float-right uk-margin-small-right"><span class="uk-text-medium uk-text-center">{{ $sample['CURRENT'] }}</span></div>
            <span class="uk-text-muted uk-text-medium">2018 YTD</span>
            <div class="clearfix"></div>
            <div class="clearfix"></div>
            <hr />
            <div class="uk-float-right uk-margin-small-right"><span class="uk-text-medium uk-text-center">{{ $sample['FULL'] }}</span></div>
            <span class="uk-text-muted uk-text-medium">2017 Full Year</span>
            <div class="clearfix"></div>
            <div class="clearfix"></div>
            <hr />
    @endforeach
</div>

更新:

这是从$ samples转储的内容

This is what dumps from $samples

array:3 [▼
0 => array:3 [▼
"employee" => "495"
"RANGE" => "PRIOR"
"COUNT" => "119"
]
1 => array:3 [▼
"employee" => "495"
"RANGE" => "CURRENT"
"COUNT" => "68"
]
2 => array:3 [▼
"employee" => "495"
"RANGE" => "FULL"
"COUNT" => "440"
]
] 

推荐答案

更改您的blade.php

Change your blade.php

<div class="md-card-content">
            <div class="uk-float-right uk-margin-small-right"><span class="uk-text-medium uk-text-center">{{ $samples[0]['COUNT'] }}</span></div>
            <span class="uk-text-muted uk-text-medium">2017 YTD</span>
            <div class="clearfix"></div>
            <div class="clearfix"></div>
            <hr />
            <div class="uk-float-right uk-margin-small-right"><span class="uk-text-medium uk-text-center">{{ $samples[1]['COUNT'] }}</span></div>
            <span class="uk-text-muted uk-text-medium">2018 YTD</span>
            <div class="clearfix"></div>
            <div class="clearfix"></div>
            <hr />
            <div class="uk-float-right uk-margin-small-right"><span class="uk-text-medium uk-text-center">{{ $samples[2]['COUNT'] }}</span></div>
            <span class="uk-text-muted uk-text-medium">2017 Full Year</span>
            <div class="clearfix"></div>
            <div class="clearfix"></div>
            <hr />

</div>

这篇关于Laravel,将新功能传递给刀片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆