Giter Site home page Giter Site logo

laracasts / laravel-5-generators-extended Goto Github PK

View Code? Open in Web Editor NEW
2.4K 87.0 346.0 138 KB

This package extends the core file generators that are included with Laravel 5

Home Page: https://laracasts.com/lessons/faster-workflow-with-generators

License: MIT License

PHP 100.00%

laravel-5-generators-extended's Issues

Pivot doesn't substitute class name.

Command:

$ ./artisan make:migration:pivot somethings otherthings
Migration created successfully.

Generates:

integer('otherthing_id')->unsigned()->index(); $table->foreign('otherthing_id')->references('id')->on('otherthings')->onDelete('cascade'); $table->integer('something_id')->unsigned()->index(); $table->foreign('something_id')->references('id')->on('somethings')->onDelete('cascade'); }); } ``` /** * Reverse the migrations. * * @return void */ public function down() { Schema::drop('otherthing_something'); } ``` }

Identifier name 'long_table_names_blah_id' is too long

Getting this error:
[PDOException] SQLSTATE[42000]: Syntax error or access violation: 1059 Identifier name 'snow_lesson_category_snow_mo nitor_snow_lesson_category_id_foreign' is too long

With this migration (or with any migration with long table names):
php artisan make:migration:pivot snow_monitors snow_lesson_categories

Can be solved by providing your own shorter key name.

$table->foreign('snow_lesson_category_id', 'snow_lesson_category_foreign')->references('id')->on('snow_lesson_categories')->onDelete('cascade');

This also happened with my primary key.

unexpected '{' while creating Pivot

I try to create a pivot:

php artisan make:migration:pivot campaigns campaignresponses

The migration file is created but when I run

php artisan migrate

I get

[Symfony\Component\Debug\Exception\FatalErrorException]        
syntax error, unexpected '{', expecting identifier (T_STRING)

What happend is that in migration file in line 6 the class name was not created an left as is

class {{class}} extends Migration

Proposal: Suggest laracasts/TestDummy in composer.json

I created my first seed files in Laravel yesterday. The code I wrote to seed the database would have been way easier if I remembered about your laracasts/TestDummy package. I propose you add it as a suggested package in composer.json. That would have really helped me.

Let me know what you think.

make:seed curly class

While creating seed with make:seed this happens


use Illuminate\Database\Seeder;

// composer require laracasts/testdummy
use Laracasts\TestDummy\Factory as TestDummy;

class {{class}} extends Seeder//
{
    public function run()
    {
        // TestDummy::times(20)->create('App\Post');
    }
}

adding {{class}} not substituting classname

Pivot doesn't render the class name

The output migration seems fine except for the class declaration, it doesn't replace the class name and this is the output:

class {{class}} extends Migration

The command was run like this: (The README didn't said you need to specify a class name, just the 2 table names)

$ php artisan make:migration:pivot users stores

Dev dependency on composer.json

"laracasts/generators": "^1.1",

make:migration:schema generates foreign constraints incorrectly

command

php artisan make:migration:schema create_posts_table --schema="user_id:integer:foreign"

generates

// ...
$table->increments('id');
$table->integer('user_id');
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
// ...

expected output

// ...
$table->increments('id');
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
$table->timestamps();
// ...

since most probably foreign keys will be used with $table->increments('id'); on other side

make:migration:schema model is empty

hi,

I tried running the following command:
hp artisan make:migration:schema create_clubs_table --schema="name:string, email:string, abbreviation:string:nullable"

And this created the right migration, but the model file it created was empty:

<?php namespace App;

use Illuminate\Database\Eloquent\Model;

class Club extends Model {

    //

}

I don't know if this is intended or not, but just wanting to point this out :)

error when require the package

when i put this command

composer require 'laracasts/generators' --dev

i have this error

[InvalidArgumentException]
Could not find package 'laracasts/generators' at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability

what's the problem ? thank you

Foreign keys

when using

"user_id:integer:foreign"

the unsigned flag needs to be added to the user_id field before the foreign_key column

e.g. this needs to create

$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');

instead of

$table->integer('user_id');
$table->foreign('user_id')->references('id')->on('users');

Lumen support?

Yo,

Will this work with Lumen? I'm not seeing any make commends in term

Thanks ~

Pivot not working correctly

When generating pivot table, the generator is putting ->unsigned() before >index() and is causing the index not to be created at the right time (I'm guessing) and causes a failure on creating the foreign keys. If I reorder and put the ->index() method first in the change, it creates the index and foreign keys

Generating pivots with tables that contain underscores in name produces incorrect class name

Hello!

I've had a go at running this:


 php artisan make:migration:pivot test_table foo_table

and the generated migration had a class name of CreateBar_tableFoo_tablePivotTable.

I'm running on Laravel 5 and pulled in (as per instructions) generators using:


 composer require laracasts/generators --dev

This created


"laracasts/generators": "^1.1"


in my composer.json

Thanks!

Tom

Command make:view?

there are plans to implement the make:view command like generate:view was on way/generators package?

I got this strange behaviour when generating the migrations.

If you run the generator command without putting a space after each of the coma separated list of the schema fields like this:
php artisan make:migration:schema create_employees_table --schema="first_name:string,last_name:string"

the generated migration file will be: $table->string,last_name('first_name')->string() which is not right.

Where as you add the space after the comma you will get the correct migration file like so:
$table->string('first_name');
$table->string('last_name');

I think there is a small bug in there.

Thanks.

Installation : USAGE step2 => return me an error :

[Symfony\Component\Debug\Exception\FatalErrorException]
syntax error, unexpected end of file, expecting function (T_FUNCTION)

I've install this under the app.php and it's ok when I do a php artisan !

Use --schema option with make:model:schema

Maybe this is in the works already? If not would it be possible to fill the migration when using make:model:schemalike so:

php artisan make:model:schema Participant --schema="firstname:string, name:string, email:string, position:string:nullable, training_id:integer:unsigned, user_id:integer:unsigned"

Pivot generator sometimes sorts columns wrong

In edge cases like when two table names overlap, the pivot generator will sort them wrong.

For example: Two tables, students and studentgroups will be sorted as studentgroup_student instead of student_studentgroup.

Suggested fix:
In PivotMigrationMakeCommand.php make sure to re-sort table names after applying str_singular on them.

I would submit a patch but I'm new to git and github, so sorry :/

model=false flag not working

I've created my migration using the following command,
Even the flag is set a Model 'EncuentrosTarjeta.php' is created under "app" folder:

php artisan make:migration:schema create_encuentros_tarjetas_table --schema="encuentro_id:integer:unsigned:foreign" --model=false

how can i use `generate:resource`

In the previous repository there was an option to use the following command. can you please tell me is there any way to this in this extended generator?
php artisan generate:resource

ambiguous class name

bug:
if a table name has an underscore , then the class name created in the migration for that table also includes an unexpected underscore.

e.g
php artisan migration:make:pivot locality time_slot
results in creation of piviot table create_locality_time_slot_pivot_table
as:
class CreateLocalityTime_slotPivotTable extends Migration
{ public function up()
{
Schema::create('locality_time_slot', function(Blueprint $table) {
$table->integer('locality_id')->unsigned()->index();
$table->foreign('locality_id')->references('id')->on('localities')->onDelete('cascade');

....}}

Is an index necessary on a foreign key column?

Maybe not exactly the right place to ask this question.. but I was wondering about the pivot table stub: is it really necessary to put ->index() on the foreign key fields? I thought that foreign key fields are always indexed automatically.

Adding a foreign column causes duplicate dropColumn

When creating a scheme with a foreign key the migration has a duplicated dropColumn line, e.g. after running this command php artisan make:migration:schema add_phone_to_users_table --schema="phone:integer:unsigned:foreign" the following migration is created

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddPhoneToUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('users', function(Blueprint $table) {
            $table->integer('phone')->unsigned();
            $table->foreign('phone')->references('id')->on('phones');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('users', function(Blueprint $table) {
            $table->dropColumn('phone');
            $table->dropColumn('phone');
        });
    }
}

Generate function with Artisan !!?

Hi everyone,
I'm looking for a way to generate code function(php ) from dashboard with laravel or just with php !!! Any help will be great :)

or a way to generate function with artisan !
Thanks in advance

(php artisan) Causes an Error in Laravel 5.2

Can anyone help, I am getting an error when I run php artisan

  [ReflectionException]                                
  Class Illuminate\Foundation\Composer does not exist 

had to remove this line to get php artisan to work

    if ($this->app->environment() == 'local') {
        $this->app->register('Laracasts\Generators\GeneratorsServiceProvider');
    }

Improvements for Pivot Tables

In my opinion a Pivot requires the $table->timestamps(); fields to support the ->withTimestamps(); function.
Also i would prefer an id field as primary key (First normal form).

Additionally a combined index between the relational id's would be a benefit for performance.

Correct me if I'm wrong

->unsigned() missing

When adding a relation with the generator, it generates for example:

            $table->integer('user_id');
            $table->foreign('user_id')->references('id')->on('users');

But then ->unsigned(); is missing on the integer itself.

Running artisan fresh after installing this package, will unregister it.

Not an "issue" but a warning. If you follow the instructions and add the provider to app/Providers/AppServiceProvider.php, upon running artisan fresh, you will have to re-add the provider as artisan fresh clears that out.

Also - if there's a better place to add comments like this, please advise me of where. :)

generate:scaffold not working at all

php artisan generate:scaffold not working at all. Its throwing error after:$ php artisan generate:scaffold {resource}

Do you want me to create a {resource} model? [yes|no] yes

[InvalidArgumentException] The "--templatePath" option requires a value.

But in the list of options after executing php artisan generate:scaffold --help there is no --templatePath And again if I try with php artisan generate:scaffold {resource} --templatePath

[RuntimeException]
The "--templatePath" option does not exist.

error

I'm getting this error:

The requested package laracasts/generators could not be found....I'm using Laravel 5.

missing documentation -- defining new column length

Hello, If i want to add a new column with migrations something like:

make:migration:schema add_password_to_users_table --schema="password:varchar"

how do I specify the field length? just looking for a reference sheet for the syntax. thanks

Generators not showing

I followed the steps as listed in the readme.md but the generators are not showing when I run php artisan

When I add the service provider to config/app.php, they do show ?

seed stub not parsing {{class}} with seed name

Hi,

Small issue: running a simple php artisan make:seed users results in no errors, but the output of UsersTableSeeder.php :

    use Illuminate\Database\Seeder;

    // composer require laracasts/testdummy
    use Laracasts\TestDummy\Factory as TestDummy;

    class {{class}} extends Seeder
    {
        public function run()
        {
            // TestDummy::times(20)->create('App\Post');
        }
    }

Version constraint error when installing

Hi, I've tried installing this using the composer command you provided and I get these errors:
[RuntimeException] Could not load package dragonrun1/phpspec in http://packagist.org: [Unexpec tedValueException] Could not parse version constraint ^1.0.1: Invalid versi on string "^1.0.1"
[UnexpectedValueException] Could not parse version constraint ^1.0.1: Invalid version string "^1.0.1"
My composer.json already seems to contain "phpspec/phpspec": "~2.1", out of the box on L5, so could there be some kind of conflict between the two?

Any help on this would be great!

when a pivot table is created, it gives wrong class name

hello Jeffery
having used this generator to create a pivot table, it did everything correct except that it gave:
class {{class}} extends Migration as the header with classname not being specified, perhaps it didn't replace the variable, perhaps it's a setup problem here but everything else is working fine.

Thanks

2 migrations files are generated on php artisan make:migration:schema.

php artisan make:migration:schema create_companies_table - schema="user_id:integer:foreign:unsign
ption:text,active:boolean,tax_no:varchar,child:boolean,child_of:integer:unsign"

This command generate two files ,

2015_05_13_084536_create_companies_table

public function up()
{
    Schema::create('companies', function(Blueprint $table) {
        $table->increments('id');
        $table->integer('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users');
        $table->string('title');
        $table->text('description');
        $table->boolean('active');
        $table->varchar('tax_no');
        $table->boolean('child');
        $table->intger('child_of')->unsign();
        $table->timestamps();
    });
}

2015_05_13_084537_create_companies_table

public function up()
{
    Schema::create('companies', function(Blueprint $table)
    {
        $table->increments('id');
        $table->timestamps();
    });
}

And in autoload class it register first migration file.
'CreateCompaniesTable' => $baseDir . '/database/migrations/2015_05_13_084536_create_companies_table.php',

Creating Migrations From a Controller

Any suggestions on creating migrations from a controller?

When running

Artisan::call('make:migration:schema', ['name' => 'create_test_table', '--schema' => 'username:string, email:string:unique']);

no migration is created.

Cannot add foreign key constraint (mysql)

When creating a schema which includes a foreign key, if you forget to add the "unsigned" option to the key, you will get a mysql error when you try to run the migration.

For instance, the README has an example regarding foreign keys, but before we use it, we need to setup the users table, so I'll do a dumb one here:

php artisan make:migration:schema create_users_table --schema="fullname:string"

This generates:

Schema::create('users', function(Blueprint $table) {
    $table->increments('id');
    $table->string('fullname');
    $table->timestamps();
);

Fine and dandy. (Note, the "increments" above creates an unsigned integer field in mysql. This is important).

So, now we move on to the example given in the docs for making a schema which relates to this new users table...

php artisan make:migration:schema create_posts_table --schema="user_id:integer:foreign, title:string, body:text"

Which generates the following:

Schema::create('posts', function(Blueprint $table) {
    $table->increments('id');
    $table->integer('user_id');
    $table->foreign('user_id')->references('id')->on('users');
    $table->string('title');
    $table->text('body');
    $table->timestamps();
);

Running this migration, you will find it will bark at you saying

General error: 1215 Cannot add foreign key constraint"

To solve the problem on the fly, just go into the create_posts_table migration file and change one line:

// $table->integer('user_id');
$table->integer('user_id')->unsigned();

Since I've not done a PR before, and don't have the time at this very moment to learn, I'll leave this up to someone else to do unless (a) it's not fixed quickly, (b) I get annoyed enough by it and (c) I get the time to learn how to do PRs. :)

Hopefully this is helpful and will spark a change.

Cheers.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.