database/seeders/ShowTagSeeder.php
/**
     * Run the database seeds.
     *
     * @return void
     */
Run the database seeds.
@return void
Run the database seeds . @return void
public function run()
    {
        DB::statement('SET FOREIGN_KEY_CHECKS=0');
        DB::table('show_tag')->truncate();
        DB::statement('SET FOREIGN_KEY_CHECKS=1');
        $showTags = [
            [
                'show_slug'=>'Ayiti',
                'tag'=>'soleil',
            ],
            [
                'show_slug'=>'Ayiti',
                'tag'=>'mer',
            ],
            [
                'show_slug'=>'cible-mouvante',
                'tag'=>'soleil',
            ],
        ];
        foreach ($showTags as &$data) {
            $show = Show::where([
                ['slug','=',$data['show_slug'] ],
            ])->first();
            $tag = Tag::firstWhere('tag',$data['tag']);
            unset($data['show_slug']);
            unset($data['tag']);
            $data['show_id'] = $show->id;
            $data['tag_id'] = $tag->id;
        }
        unset($data);
        DB::table('show_tag')->insert($showTags);
    }
public function run ( ) { DB :: statement ( 'SET FOREIGN_KEY_CHECKS=0' ) ; DB :: table ( 'show_tag' ) -> truncate ( ) ; DB :: statement ( 'SET FOREIGN_KEY_CHECKS=1' ) ; $ showTags = [ [ 'show_slug' => 'Ayiti' , 'tag' => 'soleil' , ] , [ 'show_slug' => 'Ayiti' , 'tag' => 'mer' , ] , [ 'show_slug' => 'cible-mouvante' , 'tag' => 'soleil' , ] , ] ; foreach ( $ showTags as & $ data ) { $ show = Show :: where ( [ [ 'slug' , '=' , $ data [ 'show_slug' ] ] , ] ) -> first ( ) ; $ tag = Tag :: firstWhere ( 'tag' , $ data [ 'tag' ] ) ; unset ( $ data [ 'show_slug' ] ) ; unset ( $ data [ 'tag' ] ) ; $ data [ 'show_id' ] = $ show -> id ; $ data [ 'tag_id' ] = $ tag -> id ; } unset ( $ data ) ; DB :: table ( 'show_tag' ) -> insert ( $ showTags ) ; }
Run the database seeds.
Run the database seeds .
//Empty the table first //Define data //Prepare the data //Search the artist for a given artist's firstname and lastname //Search the type for a given type //Insert data in the table