PHP code example of stidges / laravel-fk-migration

1. Go to this page and download the library: Download stidges/laravel-fk-migration library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

stidges / laravel-fk-migration example snippets




use Stidges\LaravelFkMigration\Migration;

class CreateForeignKeys extends Migration {

    /**
     * The foreign keys to create or drop.
     *
     * @var array
     */
    protected $keys = [];

}



use Stidges\LaravelFkMigration\Migration;

class CreateForeignKeys extends Migration {

    protected $keys = [
        'posts'    => [ 'column' => 'category_id' ],
        'post_tag' => [
            [ 'column' => 'post_id', 'onDelete' => 'cascade' ],
            [ 'column' => 'tag_id' ],
        ],
    ];
    
}



use Stidges\LaravelFkMigration\Migration;

class CreateForeignKeys extends Migration {

    protected $keys = [];
    
    protected $presets = [
        'user' => [ 'column' => 'user_id' ],
    ];
    
    public function getKeys()
    {
        $keys = [
            'posts'      => [ $this->presets['user'] ],
            'tags'       => [ $this->presets['user'] ],
            'categories' => [ $this->presets['user'] ],
        ];
        
        return $keys;
    }
}