I am currently designing a website using the Laravel 4.2 framework and twitter bootstrap. I have set up my master.blade.php
file which presents a navbar at the top of every page.
Basically if the user is logged in I want to display a navbar with different options than if a user is not logged in. Therefore when a user logs in I set the $_SESSION
variable.
However, when I use {{session_start();}}
in my master.blade.php file, 1 is outputted to my website. How to fix this?
![<html>
<head>
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0">
<link href="{{asset('resources/css/bootstrap.css')}}" rel="stylesheet">
<link href="{{asset('resources/css/master.css')}}" rel="stylesheet">][1]
@section('head')
@show
</head>
<body>
{{session_start();}}
@if(!isset($_SESSION['email']))
<div class="navbar navbar-inverse navbar-static-top">
<div class="container">
<div class="navbar-brand">Jordanstown Dive Club</div>
<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="home">Home</a></li>
<li><a href="login">Log In</a></li>
<li><a href="signup">Sign Up</a></li>
<li><a href="gallery">Gallery</a></li>
<li><a href="contactus">Contact Us</a></li>
</ul>
</div>
</div>
</div>
@elseif(isset($_SESSION['email']))
<div class="navbar navbar-inverse navbar-static-top">
<div class="container">
<div class="navbar-brand">Jordanstown Dive Club</div>
<button class="navbar-toggle" data-toggle="collapse" data-target=".navHeaderCollapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<div class="collapse navbar-collapse navHeaderCollapse">
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="home">Home</a></li>
<li><a href="logout">Log Out</a></li>
<li><a href="BookaDive">Book a Dive</a></li>
<li><a href="DiveLog">Dive Log</a></li>
<li><a href="gallery">Gallery</a></li>
<li><a href="contactus">Contact Us</a></li>
</ul>
</div>
</div>
</div>
@endif
{{ function() }} will be translated to PHP echo, function is executed and return value printed.
In Laravel you do not need to use session_start() as Laravel has builtin session management mechanism.
If you want different menu options then you can check if user is logged in and use @if