gpt4 book ai didi

laravel - 在 laravel AppServiceProvider 上获取错误

转载 作者:行者123 更新时间:2023-12-04 19:50:25 25 4
gpt4 key购买 nike

我正在学习 laravel 5.2 并尝试按照视频教程制作一个 cms 项目。我创建了如下文件-

应用程序/View/Composers/InjectPages.php

namespace App\View\Composers;

use App\Page;
use Illuminate\View\View;

class InjectPages
{
protected $pages;

public function __construct(Page $pages)
{
$this->pages = $pages;
}

public function compose(View $view)
{
$pages = $this->pages->all()->toHierarchy();

$view->with('pages', $pages);
}
}

应用/Providers/AppServiceProvider.php

public function boot()
{
$this->app['view']->composer('layouts.frontend', Composers\InjectPages::class);
}

资源/views/welcome.blade.php

@extends('layouts.frontend')

@section('title', 'Welcome')

@section('heading', 'This is a heading')

@section('content')

<h1>Hello World</h1>

@endsection

public/themes/views/layouts/frontend.blade.php

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>@yield('title') &mdash; Tuts24.com</title>

<link rel="stylesheet" type="text/css" href="{{ theme('css/frontend.css') }}">
</head>
<body>
<nav class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand">
<img src="{{ theme('images/logo.png') }}" alt="Tuts24.com">
</a>
</div>
<ul class="nav navbar-nav">
@include('partials.navigation')
</ul>
</div>
</nav>

<div class="container">
<div class="row">
<div class="col-md-12">
@yield('content')
</div>
</div>
</div>
</body>
</html>

public/themes/views/partials/navigation.blade.php

@foreach($pages as $page)
<li class="{{ Request::is($page->uri_wildcard) ? 'active' : '' }} {{ count($page->children) ? ($page->isChild() ? 'dropdown-submenu' : 'dropdown') : '' }}">
<a href="{{ url($page->uri) }}">
{{ $page->title }}
@if(count($page->children))
<span class="caret {{ $page->child() ? 'right' : '' }}"></span>
@endif
</a>

@if(count($page->children))
<ul class="dropdown-menu">
@include('partials.navigation', ['pages' => $page->children])
</ul>
@endif
</li>
@endforeach

但总是报如下错误。

ErrorException in Container.php line 734: Class App\Providers\Composers\InjectPages does not exist (View: /path/to/project/resources/views/welcome.blade.php)

我不确定,这些信息是否足以为您找出错误。如果需要更多信息,请告诉我。期待你的回复。谢谢。

更新-

经过多次尝试作为答案,在我看来,以下文件也与此错误有关。这就是为什么我也添加此代码并共享我的学习项目的保管箱链接。

应用/ View /ThemeViewFinder.php

<?php

namespace App\View;

use Illuminate\View\FileViewFinder;

class ThemeViewFinder extends FileViewFinder
{
protected $activeTheme;

protected $basePath;

public function setBasePath($path)
{
$this->basePath = $path;
}

public function setActiveTheme($theme)
{
$this->activeTheme = $theme;

array_unshift($this->paths, $this->basePath.'/'.$theme.'/views');
}
}

Dropbox 链接 https://www.dropbox.com/sh/v8n1qvix20hywmo/AABVcs8DqvEhI89lw98mbxbya?dl=0

最佳答案

试试这个:

composer('layouts.frontend', '\App\View\Composers\InjectPages::class');

此外,尝试运行 composer dumpauto 命令。

关于laravel - 在 laravel AppServiceProvider 上获取错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39060800/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com