laravel / nova-issues

553 stars 34 forks source link

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

Open beshoo opened 1 day ago

beshoo commented 1 day ago

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, [
                'beshoo@gmail.com'
            ]);
        });
    }

    /**
     * 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 commented 23 hours ago

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)