未找到Laravel Class'App \ Model \ Website'

时间:2017-05-31 13:51:45

标签: php laravel

我在网站模型上调用静态方法时遇到问题:Website::all()。有人可以看到一个错误,因为我不能。

堆栈跟踪

[2017-05-31 13:33:51] local.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Class 'App\Model\Website' not found in /Users/macmini2/ws/app/Services/ServiceWebsite.php:36
    Stack trace:
    #0 /Users/macmini2/ws/app/Core/Webscraper.php(212): App\Services\ServiceWebsite->findAll()
    #1 /Users/macmini2/ws/app/Core/Webscraper.php(30): App\Core\Webscraper->processWebsite('http://localhos...', Array, Array, Array, Object(App\Model\ClientService), true)
    #2 /Users/macmini2/ws/app/Main.php(32): App\Core\Webscraper->setup('http://localhos...', Array)
    #3 /Users/macmini2/ws/app/Console/Commands/cmd.php(62): App\Main->__construct('http://localhos...', Array)
    #4 [internal function]: App\Console\Commands\cmd->handle()
    #5 /Users/macmini2/ws/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(29): call_user_func_array(Array, Array)
    #6 /Users/macmini2/ws/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
    #7 /Users/macmini2/ws/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
    #8 /Users/macmini2/ws/vendor/laravel/framework/src/Illuminate/Container/Container.php(531): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
    #9 /Users/macmini2/ws/vendor/laravel/framework/src/Illuminate/Console/Command.php(182): Illuminate\Container\Container->call(Array)
    #10 /Users/macmini2/ws/vendor/symfony/console/Command/Command.php(264): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
    #11 /Users/macmini2/ws/vendor/laravel/framework/src/Illuminate/Console/Command.php(167): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
    #12 /Users/macmini2/ws/vendor/symfony/console/Application.php(835): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #13 /Users/macmini2/ws/vendor/symfony/console/Application.php(200): Symfony\Component\Console\Application->doRunCommand(Object(App\Console\Commands\cmd), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #14 /Users/macmini2/ws/vendor/symfony/console/Application.php(124): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #15 /Users/macmini2/ws/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #16 /Users/macmini2/ws/artisan(35): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #17 {main}  

这是Model类

<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Website extends Model
{
    protected $table = "websites";

    public function customer(){
        return $this->hasOne('App\Model\Customer', 'foreign_key');
    }

    public function pages(){
        return $this->hasMany('App\Model\Page');
    }

}

这是服务类

<?php

namespace App\Services;

use App\Model\Website;
use App\Services\ServiceInterface;
use App\Traits\HeaderTrait;
use App\Traits\PageTrait;
use Carbon\Carbon;

class ServiceWebsite implements ServiceInterface{

    use HeaderTrait, PageTrait;


    //Find all websites
    public function findAll(){

        return Website::all();

    }

    }

}

2 个答案:

答案 0 :(得分:3)

希望您的模型文件名为Website.php,您是否尝试运行

composer dump-autoload

答案 1 :(得分:2)

运行命令

composer dump-autoload

composer dump-autoload 命令,它不会下载任何新内容。它只是重新生成需要包含在项目中的所有类的列表。