私はLaravel5.5の初心者で、私のコマンドでモデルを使用したいのですが、
最初のphp artisan make:model MyTest、次に私はmodelを使ってmysqlからデータを取得します。
コマンドファイル:laravel 5.5コマンドの使用モデル
<?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出力は次のとおりです:
<?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();
}
}
とモデルファイルがある
[Symfony\Component\Debug\Exception\FatalThrowableError]
Class 'App\Console\Commands\App\Model\MyTest' not found
そして、私はGoogleで検索して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名前空間**の内容をもう一度読むようになります。 –