Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 1 year ago.
0

I don't think the

php artisan generate:pivot players teams

exists in Laravel 5 as it used to in Laravel 4.

Hopefully however, this may help. This is how I create pivot tables in Laravel 5 with foreign key constraints:

php artisan make:migration create_player_team_table --table=player_team

The most important thing is to ensure your player_team table name is in alphabetical order with singular table names, i.e. do not use teams_players (not alphabetical), and do not use something like, player_teams (the plural teams will break it.)

The following gives an example of how the resulting

###_##_##_######_create_player_team_table.php

up() function might look:

    /**
    * Run the migrations.
    *
    * @return void
    */
    public function up()
    {
        Schema::create('player_team', function(Blueprint $table)
        {
            $table->increments('id');
            $table->integer('player_id')->unsigned();
            $table->integer('team_id')->unsigned();

            $table->foreign('player_id')->references('id')->on('players')->onDelete('cascade');
            $table->foreign('team_id')->references('id')->on('teams')->onDelete('cascade');
        });
    }

Obviously, you can include or exclude the foreign key cascading deletes if you wish, I include them here only as a pointer.

I hope this helps.

Last updated 9 years ago.
0

EDIT: In the doc of this package, the command is :

php artisan make:migration:pivot tags posts
Last updated 9 years ago.
0

Couldn't list the the pivot method in bash

I do however this error, probably because i have already set this up.

$ composer require laracasts/generators --dev Using version ^1.1 for laracasts/generators ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating autoload files

[Symfony\Component\Debug\Exception\FatalErrorException] Call to undefined method Illuminate\Foundation\Application::getCachedCompilePath()

Script php artisan clear-compiled handling the post-update-cmd event returned with an error

[RuntimeException] Error Output:

require [--dev] [--prefer-source] [--prefer-dist] [--no-progress] [--no-update] [--update-no-dev] [--update-with-dependencies] [--ignore-platform-reqs] [--sort-packages] [packages1] ... [packagesN]

0

Sign in to participate in this thread!

Eventy

Your banner here too?

AdrianLove adrianlove Joined 16 Feb 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.