app/Console/Commands/ConvertImageableToUserImage.php
/**
     * Execute the console command.
     *
     * @return int
     */
Execute the console command.
@return int
Execute the console command . @return int
public function handle()
    {
        User::with('images')
            ->chunk(500, function($users) {
                foreach ($users as $user) {
                    if ($user->images->count() > 0) {
                        $image = $user->images->first();
                        $user->image_id = $image->id;
                        $user->save();
                    }
                }
            });
        $this->line('DONE');
        return 0;
    }
public function handle ( ) { User :: with ( 'images' ) -> chunk ( 500 , function ( $ users ) { foreach ( $ users as $ user ) { if ( $ user -> images -> count ( ) > 0 ) { $ image = $ user -> images -> first ( ) ; $ user -> image_id = $ image -> id ; $ user -> save ( ) ; } } } ) ; $ this -> line ( 'DONE' ) ; return 0 ; }
Execute the console command.
Execute the console command .