File "2016_09_30_135246_entrust_setup_tables.php"

Full path: /home/qooetu/costes.qooetu.com/database/migrations/2016_09_30_135246_entrust_setup_tables.php
File size: 7.37 B (7.37 KB bytes)
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor &nnbsp; Back

<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;

class EntrustSetupTables extends Migration
{
    /**
     * Run the migrations.
     *
     * @return  void
     */
    public function up()
    {
        
        Schema::create('roles', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->unique();
            $table->string('display_name')->nullable();
            $table->string('description')->nullable();
            $table->enum('scope',['Global','Local'])->default('Local');
            $table->integer('provider_id')->nullable();
            $table->timestamps();
        });

          DB::table('roles')->insert([
            'name' => 'Admin',
            'display_name'=>'Adminstartor',
            'description'=>'This account can be of either an individual or a company with their own fleet of vehicles',
            'created_at'=>date('Y-m-d H:i:s'),
            'updated_at'=>date('Y-m-d H:i:s'),
            'scope'=>'Global',
            
            ]);



           DB::table('roles')->insert([
            'name' => 'ResellerAdmin',
            'display_name'=>'AuthoryAdmin',
            'description'=>'This is the first Person to upload the document',
            'created_at'=>date('Y-m-d H:i:s'),
            'updated_at'=>date('Y-m-d H:i:s'),
            'scope'=>'Global',
            
            ]);

           DB::table('roles')->insert([
            'name' => 'Contractors',
            'display_name'=>'Contractors',
            'description'=>'This is the first Person to upload the document',
            'created_at'=>date('Y-m-d H:i:s'),
            'updated_at'=>date('Y-m-d H:i:s'),
            'scope'=>'Global',
            
            ]);


             DB::table('roles')->insert([
            'name' => 'County',
            'display_name'=>'CountyGovernment',
            'description'=>'This is a county among the 47 counties in Kenya',
            'created_at'=>date('Y-m-d H:i:s'),
            'updated_at'=>date('Y-m-d H:i:s'),
            'scope'=>'Global',
            
            ]);


         // Create table for associating roles to users (Many-to-Many)
        Schema::create('role_user', function (Blueprint $table) {
            $table->integer('user_id')->unsigned();
            $table->integer('role_id')->unsigned();

            $table->foreign('user_id')->references('id')->on('users')
                ->onUpdate('cascade')->onDelete('cascade');
            $table->foreign('role_id')->references('id')->on('roles')
                ->onUpdate('cascade')->onDelete('cascade');

            $table->primary(['user_id', 'role_id']);
        });

        DB::table('role_user')->insert([
            'user_id' => 1,
            'role_id'=>1,
             ]);





        // Create table for storing permissions
        Schema::create('permissions', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name')->unique();
            $table->string('display_name')->nullable();
            $table->string('description')->nullable();
            $table->enum('scope',['Global','Local'])->default('Local');
            $table->timestamps();
            
        });


           DB::table('permissions')->insert([
            'name' => 'access-backend',
             'display_name'=>'Access application Backend',
             'description'=>'Allow Users to loginto the application and perform various activitie',
            'created_at' =>date('Y-m-d H:i:s'),
            'scope'=>'Global',
            'updated_at'=>date('Y-m-d'),
            ]);

           DB::table('permissions')->insert([
            'name' => 'manage-authority_regions',
             'display_name'=>'Manage Regions',
             'description'=>'Allow authority Staff To Manage Regions',
            'created_at' =>date('Y-m-d H:i:s'),
            'updated_at'=>date('Y-m-d'),
            ]);



             DB::table('permissions')->insert([
            'name' => 'manage-projects',
             'display_name'=>'Manage Projects',
             'description'=>'Manage Projects',
            'created_at' =>date('Y-m-d H:i:s'),
            'updated_at'=>date('Y-m-d'),
            ]);


              DB::table('permissions')->insert([
            'name' => 'manage-system-settings',
             'display_name'=>'Manage System Variables',
             'description'=>'Manage Projects',
            'created_at' =>date('Y-m-d H:i:s'),
            'updated_at'=>date('Y-m-d'),
            ]);

                DB::table('permissions')->insert([
            'name' => 'manage-surveys',
             'display_name'=>'Update SRUQ',
             'description'=>'Manage all matters of sruq',
            'created_at' =>date('Y-m-d H:i:s'),
            'updated_at'=>date('Y-m-d'),
            ]);

            DB::table('permissions')->insert([
            'name' => 'View-admin-dashboard',
             'display_name'=>'View Admin Dashboard',
             'description'=>'View Admin Dashboard',
            'created_at' =>date('Y-m-d H:i:s'),
            'updated_at'=>date('Y-m-d'),
            ]);


             DB::table('permissions')->insert([
            'name' => 'view-all-estimations',
             'display_name'=>'View All Estimations',
             'description'=>'View All Estimations',
            'created_at' =>date('Y-m-d H:i:s'),
            'updated_at'=>date('Y-m-d'),
            ]);



             DB::table('permissions')->insert([
            'name' => 'manage-authorities',
             'display_name'=>'Manage Road Authorities',
             'description'=>'Create,view and delete road Authorities',
            'created_at' =>date('Y-m-d H:i:s'),
            'updated_at'=>date('Y-m-d'),
            ]);

             DB::table('permissions')->insert([
            'name' => 'manage-contractors',
             'display_name'=>'Manage Contractors',
             'description'=>'Create,view and delete road Contractors',
            'created_at' =>date('Y-m-d H:i:s'),
            'updated_at'=>date('Y-m-d'),
            ]);



               


              

         

         

            
        // Create table for associating permissions to roles (Many-to-Many)
        Schema::create('permission_role', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('permission_id')->unsigned();
            $table->integer('role_id')->unsigned();
            $table->foreign('permission_id')->references('id')->on('permissions')
                ->onUpdate('cascade')->onDelete('cascade');
            $table->foreign('role_id')->references('id')->on('roles')
                ->onUpdate('cascade')->onDelete('cascade');
        });

           DB::table('permission_role')->insert([
            'role_id' => 1,
            'permission_id'=>1,
            ]);

             DB::table('permission_role')->insert([
            'role_id' => 2,
            'permission_id'=>1,
            ]);

           
    }

    /**
     * Reverse the migrations.
     *
     * @return  void
     */
    public function down()
    {
        Schema::drop('permission_role');
        Schema::drop('permissions');
        Schema::drop('role_user');
        Schema::drop('roles');
    }
}