skip to Main Content

I am trying to send a lot of stats to my dashboard view but I am having undefined variable errors for all the passed variables.
My controller is

public function index(Request $request)
    {
        
        $user = Auth::user();
        $company_id = $user->company_id;

        $data['emps'] = 600;
        $data['docs'] = 500;

        // $data['users'] = User::where([
        //     'company_id' => $company_id
        // ])->get()->count();

        

        $data['recent_docs'] =[];
        $data['count'] = 1500;
        
        return view('home', $data);
    }

In my view I am trying to access the passed values like this

<div class="col-md-3">
            <x-adminlte-info-box 
                text={{$count}}
                title="Documents"
                theme="gradient-purple"
                icon="fas fa-lg fa-copy text-yellow"
                icon-theme="red"
            />
        </div>
        <div class="col-md-3">
            <x-adminlte-info-box 
                text={{$docs}}
                title="Employees"
                icon="fas fa-lg fa-users text-primary"
                theme="gradient-primary" icon-theme="white"
            />
        </div>

2

Answers


  1. Chosen as BEST ANSWER

    There was an issue with the routes file that is fixed. Thankyou Stackoverflow community for being so nice always.


  2. I see that you are using blade component. In the docs there’s information that

    You may pass data to Blade components using HTML attributes. Hard-coded, primitive values may be passed to the component using simple HTML attribute strings. PHP expressions and variables should be passed to the component via attributes that use the : character as a prefix

    So you should use the $count in your template like that:

    <div class="col-md-3">
        <x-adminlte-info-box 
            :text="$count"
            title="Documents"
            theme="gradient-purple"
            icon="fas fa-lg fa-copy text-yellow"
            icon-theme="red"
        />
    </div>
    <div class="col-md-3">
        <x-adminlte-info-box 
            :text="$docs"
            title="Employees"
            icon="fas fa-lg fa-users text-primary"
            theme="gradient-primary" icon-theme="white"
        />
    </div>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search