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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34339517/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:55:26  来源:igfitidea点击:

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

phplaravel-5.1lumen

提问by Samuel Dauzon

I use Lumen 1.0 for an API project.

我将 Lumen 1.0 用于 API 项目。

I have already enable Eloquent by uncomment the following line in bootstrap/app.phpfile :

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

$app->withEloquent();

But when I want to create my first model with migration it fails :

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

php artisan make:model Book --migration

Error message :

错误信息 :

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

Laravel doc about Eloquent (http://laravel.com/docs/5.1/eloquent#defining-models).

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

Lumen doc (http://lumen.laravel.com/docs/installation) doesn't include Eloquent doc because, it's not enable by default.

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

Do you have any ideas to avoid this error ?

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

Add details

添加详细信息

php artisan --version

Displays :

显示:

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

回答by Rwd

You're seeing this error because Lumen doesn't come with make:model.

您看到此错误是因为 Lumen 没有附带make:model.

To see a list of all the artisan commands you have at your disposal just run php artisan.

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

That being said I did just find this package which I've added to a lumen installation and it seems to work fine https://github.com/webNeat/lumen-generators#installation

话虽如此,我确实找到了我添加到 lumen 安装中的这个包,它似乎运行良好https://github.com/webNeat/lumen-generators#installation

Hope this helps!

希望这可以帮助!

回答by Thushan

  1. Go to the project directory and add the generators package to your composer.jsonusing the following command:

    composer require wn/lumen-generators
    
  2. Add following code segment to app/Providers/AppServiceProvider.php:

    public function register()
    {
        if ($this->app->environment() == 'local') {
            $this->app->register('Wn\Generators\CommandsServiceProvider');
        }
    }
    
  3. Make sure that you have un-commented the following line in bootstrap/app.phpto allow service providers on your project:

    $app->register(App\Providers\AppServiceProvider::class);
    
  4. Run php artisan liston the project directory (document root). Now you will see new items there.

  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该项目目录(文档根目录)。现在您将在那里看到新项目。

回答by johannchopin

If you check all the available commands using php artisan listyou will see that you don't have all the default ones offered by laravel. But you can get the most importants using the lumen-generatorpackage (not to be confused with lumen-generators). It has the advantage of offering more commands than the other one mentioned.

如果您使用检查所有可用命令,php artisan list您将看到您没有提供的所有默认命令laravel。但是您可以使用该lumen-generator包获得最重要的信息(不要与 混淆lumen-generators)。它的优点是提供比提到的另一个命令更多的命令。

To use it just install it using composer:

要使用它,只需使用composer以下命令安装它:

composer require flipbox/lumen-generator

Then enable it in your bootstrap/app.phpfile:

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

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

You will now be able to use all these new commands using artisan:

您现在可以使用以下命令使用所有这些新命令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

Just have a look at the official documentation: https://github.com/flipboxstudio/lumen-generator

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

回答by yas17

just create your model file manually in the app directory

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

example

例子

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

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

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