skip to Main Content

resources / views / layouts / navigation.blade .php : 8 require

in my home page Laravel

<!-- resources/views/page.blade.php -->
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Front Page</title>
    </head>
    <body>
        <!-- Include the navigation menu -->
        @include('layouts.navigation')

        <!-- Your front page content goes here -->
        <h1>Welcome to the front page</h1>
        <p>This is the content of your front page.</p>
    </body>
</html>


and my layout navigation

i have error in this line : @if (auth()->user()->manages())

Call to a member function manages() on null

Expand vendor frames resources / views / layouts / navigation.blade .php : 8 require 9 vendor frames resources / views / welcome.blade .php : 10 require 56 vendor frames public / index .php : 51 require_once 1 vendor frame

2

Answers


  1. That means, you dont have an authenticated user, so check first if auth()->user() exists, like:

      @if (!is_null(auth()->user())) //if auth()->user() is not null, you can call the manages() function on it
         @if(auth()->user()->manages())
           //content you want
         @endif
      @endif
    
    Login or Signup to reply.
  2. You can use the optional helper from laravel.

    It allows you to call methods or access properties off of objects, if the object is null, instead of throwing an error, null is returned ie;

    @if (optional(auth()->user())->manages())
    
    // your template stuff
    
    @endif
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search