app/Console/Commands/ConvertImageablesToContentImage.php
/**
     * Execute the console command.
     *
     * @return int
     */
Execute the console command.
@return int
Execute the console command . @return int
public function handle()
    {
        Content::with('images')
            ->whereIn('type', ['flight', 'news', 'shortnews', 'photo'])
            ->chunk(500, function($contents) {
                foreach ($contents as $content) {
                    if ($content->images->count() > 0) {
                        $image = $content->images->first();
                        $content->image_id = $image->id;
                        $content->save();
                    }
                }
            });
        $this->line('DONE');
        return 0;
    }
public function handle ( ) { Content :: with ( 'images' ) -> whereIn ( 'type' , [ 'flight' , 'news' , 'shortnews' , 'photo' ] ) -> chunk ( 500 , function ( $ contents ) { foreach ( $ contents as $ content ) { if ( $ content -> images -> count ( ) > 0 ) { $ image = $ content -> images -> first ( ) ; $ content -> image_id = $ image -> id ; $ content -> save ( ) ; } } } ) ; $ this -> line ( 'DONE' ) ; return 0 ; }
Execute the console command.
Execute the console command .