2

i am new to larvel.I tried to pass the variable from controller toview but it did not worked. i am getting an error:

"Whoops, looks like something went wrong."

code used in controller:

public function showWelcome()
{
return View::make('hello', array('theLocation' => 'NYC'));
}

Code in hello.blade.php:

<h1 class="highlight">Blade has arrived in {{ $theLocation }} .</h1>

can you tell me is there any syntax error in the above code and is there any possibility of debugging the error??

6
  • Possible duplicate of Passing data from controller to view in Laravel Commented Mar 7, 2017 at 11:08
  • I don't think that's where the problem is. I think you didn't set Laravel up correctly. You'll need to do some debugging. 1.if it's development environment I suggest you edit .env (root of application) and set APP_DEBUG=true for more expressive errors. If it's prod environment I suggest you to trace the error in storage/logs/laravel.log. Commented Mar 7, 2017 at 11:11
  • where will i find .env in the root folder of laravel as i have installed in wamp serve @devk k Commented Mar 7, 2017 at 11:24
  • @PullataPraveen I don't know how you have your Laravel app set up. But it's in the root directory of the app. As in here. When setting up a new project you usually have to copy the .env.example to .env and set up the configuration you need. Commented Mar 7, 2017 at 11:57
  • 1
    @PullataPraveen well this indicates that the code you posted has nothing to do with the error you're getting :p. You're missing $theLocation in your welcome.blade.php view and not in your hello.blade.php view (which is the one you posted). Commented Mar 7, 2017 at 13:55

2 Answers 2

2

There are many ways to pass data from Controller to View like:

return view('hello')->with(['key' => 'value']);

or

return view('hello', ['key' => 'value']);

And you can use it on view like:

<p>{{ $key }}</p>
Sign up to request clarification or add additional context in comments.

Comments

1

Controller

return view('hello')->with(['theLocation' => 'NYC']);

View

<h1 class="highlight">Blade has arrived in {{ $theLocation }} .</h1>

Comments

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.