-2

i am beginner in programming and in laravel, and i have some issue about my code/project. I want a condition where my main web menu can only be accessed by auth user, but i have an error when make condition in the code. Please help me fix this problem

*ps sory for bad english

here the views

<!DOCTYPE html>
<html lang="en">
<head>
  <title>DOKO MOTOR</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <link rel="stylesheet" href="{{url('/')}}/css/lwd.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>

<div id="top-header" style="background:#FFF;height: 100px;"s>
<div id="header" class="hidden-sm hidden-xs">
  <img src="{{url('/')}}/img/logo.png" height="90px" style="position: absolute;">
  <div class="bendera"></div>
              <div class="hotline pull-right">
                  <div class="left"><i class="glyphicon glyphicon-earphone" style="
    font-size: 50px; color:red;
"></i></div>
                    <div class="right">
                    <div class="r-top">hotline :</div>
                        <div class="r-bot">0896 5200 6229</div>
                    </div>
                    <div class="break"></div>
                </div><!-- /.hotline -->
                <div class="top-wel pull-right">Selamat datang di website kami, Jumat, 11 Mei 2018 </div>
</div><!-- /#header -->

</div>

<nav class="navbar navbar-default">
  <div class="container-fluid">
    <div class="navbar-header">
      <a class="navbar-brand" href="{{ url("") }}">DOKO MOTOR</a>
    </div>
    <ul class="nav navbar-nav">
      <!-- @if(Auth::user()) -->
      @if(Auth::user())
      <li class="{{ request()->is('book') ? 'active' : '' }}"><a href="{{ url("book") }}"><span class="glyphicon glyphicon-wrench"></span> Book Service</a></li>
      <!-- @endif -->
      <li class="{{ request()->is('services') ? 'active' : '' }}"><a href="{{ url("services") }}"><span class="glyphicon glyphicon-hourglass"></span> Antrian Service</a></li>
      <li class="{{ request()->is('contact') ? 'active' : '' }}"><a href="{{ url("contact") }}"><span class="glyphicon glyphicon-user"></span> Kontak</a></li>
      <li class="{{ request()->is('tentang') ? 'active' : '' }}"><a href="{{ url("tentang") }}"><span class="glyphicon glyphicon-earphone"></span> Tentang</a></li>


    </ul>
    <ul class="nav navbar-nav navbar-right">
      <!-- @if(Auth::user()) --> 
      <li><a href="{{URL::to('/logout')}}">
      <span style="color: blue"> {{ ucwords(Auth::user()->name) }}</span> <span class="glyphicon glyphicon-log-in"></span> Logout</a></li>
      <!-- @else -->
      @else

      <li><a href="{{URL::to('/register')}}"><span class="glyphicon glyphicon-user"></span> Daftar</a></li>
      <li><a href="{{URL::to('/signin')}}"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
      <!-- @endif -->
      @endif
    </ul>
  </div>
</nav>

<div class="container">
  @yield('content')
</div>

<div id="footer">


        <div class="row">
          <div class="col-md-12">
              <div class="copy">Copyright © 2018 -  All rights reserved.</div>
            </div>
        </div><!-- /.row -->
</div>
</body>
</html>

here the route

Route::get('/signin', function() {
    return view('login');
});

Route::get('/register/{date?}', function($date = null) {
    return view('register',['date',$date]);
});

Route::post('/register_action/{date?}','RegisterController@store');

Route::post('/login_check','RegisterController@login');

Route::get('logout', function() {
    Auth::logout();

    return Redirect::to('');
})->middleware("auth");

Route::get('/', function(){
    if( auth()->check() ){
        return Redirect::to('/');
    }else{
        return Redirect::to('/auth');   
    }
});

Route::get('/', 'HomeController@index');

Route::get('/contact','ContactController@index');

Route::get('/tentang','TentangController@index');

Route::get('/book/{date?}', 'ServisController@book');

Route::get('/services/{add?}', 'ServisController@services');

Route::post('/submit_book', 'ServisController@submit_book'); 

Route::post('/update_service', 'ServisController@update_service'); 

Route::post('/delete_service', 'ServisController@delete_service');

error message

I'll appreciate anything would help me

Kindly regards

Realalun
  • 35
  • 1
  • 2
  • 7

1 Answers1

0

Try changing the way you structure your html:

@if(Auth::user())
<ul class="nav navbar-nav">
  <li class="{{ request()->is('book') ? 'active' : '' }}"><a href="{{ url("book") }}"><span class="glyphicon glyphicon-wrench"></span> Book Service</a></li>
  <li class="{{ request()->is('services') ? 'active' : '' }}"><a href="{{ url("services") }}"><span class="glyphicon glyphicon-hourglass"></span> Antrian Service</a></li>
  <li class="{{ request()->is('contact') ? 'active' : '' }}"><a href="{{ url("contact") }}"><span class="glyphicon glyphicon-user"></span> Kontak</a></li>
  <li class="{{ request()->is('tentang') ? 'active' : '' }}"><a href="{{ url("tentang") }}"><span class="glyphicon glyphicon-earphone"></span> Tentang</a></li>
</ul>
@endif
<ul class="nav navbar-nav navbar-right">
  @if(Auth::user())
  <li><a href="{{URL::to('/logout')}}">
  <span style="color: blue"> {{ ucwords(Auth::user()->name) }}</span> <span class="glyphicon glyphicon-log-in"></span> Logout</a></li>
  @else
  <li><a href="{{URL::to('/register')}}"><span class="glyphicon glyphicon-user"></span> Daftar</a></li>
  <li><a href="{{URL::to('/signin')}}"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
  @endif
</ul>

The way you write your HTML must make sense after the if statements, to visualise this try removing the code that a situation would create, so if the user isn't there remove that code and see what you are left with, at the moment you would have HTML that wouldn't make sense and the browser wouldn't be able to present it in the way you would like

Lewis Smith
  • 1,271
  • 1
  • 14
  • 39