1

Controller Code:

    public function claims($id)
    {
        $claims = Claim::whereBetween('created_at', [
                            '2016-03-01', 
                            '2016-03-31'
                        ])->get();

        return View::make('pdfs.view', $claims);

    }

In my view I'm getting a message that $claims is an undefined variable.

I know that with a single array I can simply access the array properties by callig a variable of the same name. i.e. $claims['id] would simply by $id

However I cannot do this with a multidimensional array, as $claims does not exist

Also, I cannot pass the data as an object using ->with('claims' $claims) as I'm generating a PDF and the library does not support that function.

Any ideas how I can access the data?

1 Answer 1

2

Because your array doesn't contains that key

return View::make('pdfs.view', $claims);

instead you can use compact like as

return View::make('pdfs.view', compact('claims'));

Or you need to do it somewhat assigning your values to same key like as

$claims['claims'] = Claim::whereBetween('created_at', [
                        '2016-03-01', 
                        '2016-03-31'
                    ])->get();
return View::make('pdfs.view', $claims);

or you can simply use Laravels way using with variable like as

return View::make('pdfs.view')->withClaims($claims);

Note : While using compact make sure your variable name must matches your string

Sign up to request clarification or add additional context in comments.

2 Comments

compact is a shortcut for ['claims'=>$claims], just so you know what is at work here. Variables passed to views this way are supposed to be in associative arrays.
Glad it helped you. @user1105056

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.