流明 (Laravel) Eloquent php artisan make:model 未定义

Lumen (Laravel) Eloquent php artisan make:model not defined

我将 Lumen 1.0 用于一个 API 项目。

我已经通过取消注释 bootstrap/app.php 文件中的以下行来启用 Eloquent:

$app->withEloquent();

但是当我想创建我的第一个迁移模型时它失败了:

php artisan make:model Book --migration

错误信息:

  [InvalidArgumentException]
  Command "make:model" is not defined.
  Did you mean one of these?
      make:seeder
      make:migration

Laravel 关于 Eloquent (http://laravel.com/docs/5.1/eloquent#defining-models) 的文档。

Lumen 文档 (http://lumen.laravel.com/docs/installation) 不包含 Eloquent 文档,因为它默认未启用。

你有什么想法可以避免这个错误吗?

添加详细信息

php artisan --version

显示器:

Laravel Framework version Lumen (5.1.6) (Laravel Components 5.1.*)

您看到此错误是因为 Lumen 未随 make:model

要查看您可以使用的所有 artisan 命令的列表,只需 运行 php artisan

也就是说我确实找到了这个我已经添加到 lumen 安装中的包,它似乎工作正常 https://github.com/webNeat/lumen-generators#installation

希望对您有所帮助!

  1. 转到项目目录并使用以下命令将生成器包添加到您的 composer.json

    composer require wn/lumen-generators
    
  2. 将以下代码段添加到 app/Providers/AppServiceProvider.php:

    public function register()
    {
        if ($this->app->environment() == 'local') {
            $this->app->register('Wn\Generators\CommandsServiceProvider');
        }
    }
    
  3. 确保您已取消注释 bootstrap/app.php 中的以下行以允许服务提供商参与您的项目:

    $app->register(App\Providers\AppServiceProvider::class);
    
  4. 运行 php artisan list 在项目目录(文档根目录)上。现在你会在那里看到新项目。

只需在应用程序目录中手动创建模型文件

示例

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;

class Article extends Model {
    protected $table = ‘articles’;

    protected $fillable = [
        ‘title’,
        ‘description’,
        ‘body’
    ];
}

如果您使用 php artisan list 检查所有可用命令,您会发现您没有 laravel 提供的所有默认命令。但是您可以使用 lumen-generator 包获取最重要的信息(不要与 lumen-generators 混淆)。它的优点是提供比其他提到的命令更多的命令。

要使用它,只需使用 composer:

安装它
composer require flipbox/lumen-generator

然后在您的 bootstrap/app.php 文件中启用它:

$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);

您现在可以使用所有这些新命令 artisan:

key:generate      Set the application key

make:command      Create a new Artisan command
make:controller   Create a new controller class
make:event        Create a new event class
make:job          Create a new job class
make:listener     Create a new event listener class
make:mail         Create a new email class
make:middleware   Create a new middleware class
make:migration    Create a new migration file
make:model        Create a new Eloquent model class
make:policy       Create a new policy class
make:provider     Create a new service provider class
make:seeder       Create a new seeder class
make:test         Create a new test class

看看官方文档:https://github.com/flipboxstudio/lumen-generator

$app->注册(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);将此行添加到“bootstrap\app.php”并保存此文件,然后使 command.It 生效。

有一些软件包可以帮助您拥有在 Laravel 上拥有的所有 artisan 命令。 安装下面的包以获得更多的 artisan 命令。 https://github.com/flipboxstudio/lumen-generator