PHP code example of triasrahman / jsonseeder

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

    

triasrahman / jsonseeder example snippets




use Illuminate\Database\Seeder;
use Triasrahman\JSONSeeder\JSONSeeder;

class YourTableSeeder extends Seeder
{
	use JSONSeeder;

	...


    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->JSONSeed('countries', '\App\Country');
    }
}


$this->JSONSeed('posts', '\App\Post', [

	// has many
	'picture' => [
	'table' => 'pictures',          // Table name (optional). If blank, it will pluralize from the name
	'class' => '\App\Picture',      // Define the related class
	'foreign_key' => 'post_id',     // Define the foreign key in related class
	'flush' => true,                // If true, it will flush the related table (optional, default: false)
	],
	
	// many to many
	'categories' => 
	'table' => 'categories',        // Table name (optional). If blank, it will pluralize from the name
	'class' => '\App\Category',     // Define the related class
	'flush' => true,                // If true, it will flush the related table (optional, default: false)
	'many_to_many' => true,         // If this relation is many to many, set it true
	],
	
	// belongs to
	'author' => [
	'table' => 'users',             // Table name (optional). If blank, it will pluralize from the name
	'class' => '\App\User',         // Define the related class
	'local_key' => 'user_id',       // Define the local key in related class
	'flush' => true,                // If true, it will flush the related table (optional, default: false)
	],
]);