laravel View Composer-发送foreach数据以查看刀片

时间:2019-02-26 00:24:47

标签: php laravel-5

好几个小时以来,我一直在弄弄它,只是似乎无法弄清楚。我正在从某些用户收集数据,然后我想打印出所有数据并将其发送给每个用户的视图刀片。

到目前为止我的代码

        view()->composer('dashboard.index', function (View $view) {
        $currency = Config::whereKey('currency')->first()->value;
        $user = auth()->user();

        $users = User::select('id','name','type','pay_rate','country_id')
        ->where('type', '=', 'country_manager')
        ->orderBy('country_id','ASC')
        ->get();

        if($users) {
           foreach ($users as $u) {
            $uid = $u->id;
            $name = $u->name;
            $type = $u->type;
            $pay = $u->pay_rate;
            $countryid = $u->country_id;

            if($type == 'country_manager'){ $role = 'Country Manager'; }
            if($type == 'team_leader'){ $role = 'Team Leader'; }
            if($type == 'moderator'){ $role = 'Moderator'; }
            if($type == 'suspend'){ $role = 'Suspended'; }    

            $sent = '0';
            $reply = '0';
            $earn = '0';

            $data = '<div class="divTableCell">'.$name.'</div>
            <div class="divTableCell">'.$countryid.'</div>
            <div class="divTableCell">'.$role.'</div>
            <div class="divTableCell">'.$pay.' '.$currency.'</div>
            <div class="divTableCell">'.$sent.'</div>
            <div class="divTableCell">'.$reply.'</div>
            <div class="divTableCell">'.$earn.' '.$currency.'</div>';


            }
        }

    $view->with(compact('data'));

    });

我知道数据正在正确收集,但是只是不知道如何从View Composer脚本打印视图页面。

0 个答案:

没有答案