简体   繁体   English

Laravel 6 View Composer 目标类不存在

[英]Laravel 6 View Composer Target Class does not exist

my Composer Service Provider is as follows:我的 Composer 服务提供商如下:

<?php

namespace App\Providers;


use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
use Illuminate\Http\Request;
use App\Http\ViewComposers\DashboardComposer;
use App\companies;
use App\user;

class ComposerServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        View::composer('layouts.dashboard', DashboardComposer::class);
    }
}

my DashboardComposer is as follows:我的 DashboardComposer 如下:

<?



namespace App\Http\ViewComposers;


use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use Illuminate\Http\Request;
use App\companies;
use App\user;


class DashboardComposer
{

    public function compose(View $view)
    {
        $user = Auth::user();
        $company = companies::findOrFail($user->companyID);
        $view->with(['user' => $user, 'company' => $company]);
     }
}

my config/app.php is as follows:我的 config/app.php 如下:

App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
App\Providers\ComposerServiceProvider::class,

], ],

my file structure is as follows:我的文件结构如下:

文件结构图

my error as is follows:我的错误如下:

我的错误

I am at a loss as to what I have done wrong.我对我做错了什么感到茫然。 I used PHP artisan to make the provider and the composer, i have done composer dumpautoload , I have cleared all the caches, I have double and triple checked my spelling, I feel like I maybe just missing a step to register the class or something but I just don't know for sure and i'm tired of guessing.我使用 PHP artisan 来制作提供程序和作曲家,我已经完成了composer dumpautoload ,我已经清除了所有缓存,我已经两次和三次检查了我的拼写,我觉得我可能只是错过了注册课程的步骤或其他什么但是我只是不确定,我厌倦了猜测。

Any advice would be appreciated, Thanks in advance!!任何建议将不胜感激,提前致谢!!

Your opening tag on the Composer class is <?您在 Composer 类上的开始标记是<? , should be <?php . , 应该是<?php Short tags are disabled by default, so this is not a valid opening tag in PHP 5/7 unless you turn it on in php.ini默认情况下禁用短标签,因此这在 PHP 5/7 中不是有效的开始标签,除非您在 php.ini 中打开它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM