lundi 25 février 2019

laravel view composer - send foreach data to view blade

ok been messing with this for a few hours now, just can't seem to figure it out. I am collecting data from certain users, then I want print out all the data and send it to the view blade for each user.

my code so far

        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'));

    });

I know the data is collecting correctly, but just do not know how to print it view page from the view composer script.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire