Level 25
Jan 28, 2015
2
Level 1
Session global variable not showing in my view?
Hi Everyone
I created a search function on my website. When a user searches and zero results appear I want a message to appear that says "no results found. try again"
I attempted to do this via laravel 4 session variable. I created a variable called "global". I'm trying to echo this variable out onto my view but it's not working. My question is, what am I doing wrong? How can I get my message to appear on my website?
My Controller
public function postUseSearch(){
$searchString = Input::get('keyword');
$string = str_replace(',', '', $searchString);
$string = str_replace('\'', '', $string);
$insert = new Searchword();
$useTheFunction = new theClass();
$keyword = $useTheFunction->searchNames($string);
if(count($keyword) > 0){
$insert->keyword = $string;
$insert->blank = '1';
$insert->save();
return View::make('search.searchresults')
->with('keyword', $keyword);
} else {
$insert->keyword = $string;
$insert->blank = '0';
$insert->save();
return View::make('search.searchresults')
->with('global', 'no results found. try again');
}
}
My View
@if((Session::get('global')))
<p>{{ Session::get('global') }}</p>
@endif
Please or to participate in this conversation.