• 5
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

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

I use Lumen 1.0 for an API project.

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

$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).

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

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.*)
  1. Go to the project directory and add the generators package to your composer.json using 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.php to allow service providers on your project:

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

  • 12
Reply Report

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

To use it just install it using composer:

composer require flipbox/lumen-generator

Then enable it in your bootstrap/app.php file:

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

You will now be able to use all these new commands using 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

  • 5
Reply Report

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’
    ];
}
  • -1
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions