PHP code example of patinthehat / laravel-support

1. Go to this page and download the library: Download patinthehat/laravel-support 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/ */

    

patinthehat / laravel-support example snippets


use App\Support\ExtendedSeeder;
use App\User;

class UserTableSeeder extends ExtendedSeeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //disable foreign key checks, delete all existing table entries
        $this->init('users', true, true); 
        //seed the table
        $text = $this->getFaker()->text();
        $this->cleanup();
    }
}

use LaravelSupport\Database\ExtendedMigration;

class CreateForeignKeys extends ExtendedMigration
{
    //define the FKs
    protected $foreignKeyDefinitions = [
        'info.author_id' => ['authors.id', 'cascade', 'cascade'],
        'info.book_id' => ['books.id', null, null],
        'table2.test_id' => 'tests.id',
        'myinfo.publisher_id' => null, //creates FK on 'publishers.id'
    ];
    
    //automatically create/delete FKs
    protected $autoCreateDefinedKeys = true;
    protected $autoDeleteDefinedKeys = true;
}