Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call to a member function authorizedToSee() on null (View: \vendor\laravel\nova\resources\views\layout.blade.php) #6568

Closed
beshoo opened this issue Oct 26, 2024 · 9 comments
Labels
needs more info More information is required

Comments

@beshoo
Copy link

beshoo commented Oct 26, 2024

  • Laravel Version: 10.x
  • Nova Version: 4.34.3
  • PHP Version: 8.2
  • Database Driver & Version:
  • Operating System and Version: Windows

Description:

Once I add this to novaServiceProvider

 Nova::mainMenu(function (Request $request) {
            return [
                MenuSection::dashboard(User::class)->icon('chart-bar'),
            ];
        });
<?php

namespace App\Providers;

use Illuminate\Support\Facades\Gate;
use Laravel\Nova\Menu\MenuSection;
use Laravel\Nova\Nova;
use Laravel\Nova\NovaApplicationServiceProvider;
use Illuminate\Http\Request;

use App\Nova\User;

class NovaServiceProvider extends NovaApplicationServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();
        //Nova::enableRTL();
        Nova::initialPath('/resources/users');

        Nova::mainMenu(function (Request $request) {
            return [
                MenuSection::dashboard(User::class)->icon('chart-bar'),
            ];
        });

    }

    /**
     * Register the Nova routes.
     *
     * @return void
     */
    protected function routes()
    {
        Nova::routes()
                ->withAuthenticationRoutes()
                ->withPasswordResetRoutes()
                ->register();
    }

    /**
     * Register the Nova gate.
     *
     * This gate determines who can access Nova in non-local environments.
     *
     * @return void
     */
    protected function gate()
    {
        Gate::define('viewNova', function ($user) {
            return in_array($user->email, [
                '[email protected]'
            ]);
        });
    }

    /**
     * Get the dashboards that should be listed in the Nova sidebar.
     *
     * @return array
     */
    protected function dashboards()
    {
        return [
            new \App\Nova\Dashboards\Main,
        ];
    }

    /**
     * Get the tools that should be listed in the Nova sidebar.
     *
     * @return array
     */
    public function tools()
    {
        return [];
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

image

@crynobone
Copy link
Member

Unable to reproduce the issue, please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

@crynobone crynobone added the needs more info More information is required label Oct 26, 2024
@crynobone
Copy link
Member

@beshoo Your screenshot explicitly shown multiple middleware that doesn't exist in a vanilla Laravel Nova installation. Instead of just a thumb down did you even test it in a basic Laravel Nova installation and see if the problem exists?

@beshoo
Copy link
Author

beshoo commented Oct 28, 2024

Thank you for your reply, I am very sorry I did not mean to give a thumbs down! but thump up LOL.
And yes on a fresh installation I have the same error but on different file
image

@beshoo
Copy link
Author

beshoo commented Oct 28, 2024

I sent an email to Nova [email protected] with the zip file of the complete fresh project for further review, since the Nova script is not open-source.

@crynobone
Copy link
Member

CleanShot 2024-10-29 at 11 14 56

I did not get any issues from the files your provided, just

composer install
php artisan migrate
composer run serve

and everything is shown correctly

@crynobone
Copy link
Member

CleanShot 2024-10-29 at 11 18 10

The class expect class string instance of Laravel\Nova\Dashboard and you provides MenuSection::dashboard(\App\Nova\User::class)->icon('chart-bar')

@beshoo
Copy link
Author

beshoo commented Oct 29, 2024

I dont follow since am following the documentation

image

Please provide the correct useg!

@beshoo
Copy link
Author

beshoo commented Oct 29, 2024

@crynobone

And following the documentation leads to the previous error.
I am unsure how to pass it as a string since there is no documentation about it.

image

image

@beshoo
Copy link
Author

beshoo commented Oct 29, 2024

Solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more info More information is required
Projects
None yet
Development

No branches or pull requests

2 participants