【发布时间】:2017-11-07 19:32:49
【问题描述】:
我是 Laravel5.5 的新手,想在我的命令中使用模型,
首先 php artisan make:model MyTest,然后我使用模型从 mysql 获取数据。
命令文件:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Model\MyTest;
class UboxDataAnalysis extends Command
{
//...
public function handle()
{
$this->line('Then start query');
$o = new App\Model\MyTest();
}
}
模型文件是:
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use DB;
class MyTest extends Model
{
//
function get_data(){
$uboxTest = DB::connection('mysql-test');
$res = $uboxTest::table('m_user')->where('user_id',166);
var_dump($res);
}
}
但是 CLI 输出是:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'App\Console\Commands\App\Model\MyTest' not found
我用谷歌搜索了一些关于laravel5.5 doc的信息。To get started, let's create an Eloquent model. Models typically live in the app directory, but you are free to place them anywhere that can be auto-loaded according to your composer.json file.
也就是说,我需要在 composer.json 中添加一些配置吗?
有人可以给我一些建议吗?思考。
【问题讨论】:
标签: php laravel-5.5