Search code examples
phplaravellaravel-4laravel-3

Laravel Passing variable not working


Hello People here is my code i have used in controller...

public function bulk()
{
    return View::make('bulk')->with('message','hii there');

}

my route file contains...

Route::get('bulk',array('uses'=>'HomeController@bulk'))->before('auth');

In my view Iam testing it by ...

@if(Session::has('message')) 
Present
@else
not Present
@endif

The page is making a view with the message 'not Present' why is it?? I even tried

return Redirect::to('bulk')->with('message','hii there');

I get an erro mesage on Console

 mypro/public/bulk net::ERR_TOO_MANY_REDIRECTS 

What could be the problem?? is there any issues with name?? I tried this method earlier which worked fine for me.... :(

Iam using Blade Template..


Solution

  • You are confusing Redirect and View. You use Session::get to access variables passed to redirects. For views (as in your case), with will pass an simple PHP variable into your view. So your check should be:

    @if(isset($message)) 
      {{{ $message }}}
    @else
      No message!
    @endif
    

    Read more here