未找到Laravel 5 Class'Category'

未找到Laravel 5 Class'Category'

问题描述:

I've installed Baum on laravel 5 and ran php artisan baum:install Category, which created Category class that look like this:

<?php
use Baum\Node;

class Category extends Node {
}

When I try to run:

$root = Category::create(['name' => 'Root category'])

I get the error:

 [Symfony\Component\Debug\Exception\FatalErrorException]
 Class 'Category' not found

I ran composer dump-autoload, but it did not help.

我在laravel 5上安装了Baum并运行 php artisan baum:install Category code>, 创建了如下所示的 Category em>类: p>

 &lt;?php 
use Baum \ Node; 
 
class Category extends node {
  } 
  code>  pre> 
 
 

当我尝试运行时: p>

  $ root = Category :: create(['name'  =&gt;'根类别'])
  code>  pre> 
 
 

我收到错误: p>

  [Symfony \ Component \  Debug \ Exception \ FatalErrorException] 
找不到类'类别'
  code>  pre> 
 
 

我运行 composer dump-autoload code>,但它没有帮助 。 p> div>

your declaration need to set the namespace.

<?php
namespace App; // use your app namespace
use Baum\Node;

class Category extends Node {
}

when you'll run, you can use full namespace call or with 'use' stat.

$root = App\Category::create(['name' => 'Root category']);

or

use App\Category;

$root = Category::create(...);