app/Console/Commands/ParseApartments.php
/**
     * Execute the console command.
     *
     * @return mixed
     */
Execute the console command.
@return mixed
Execute the console command . @return mixed
public function handle()
    {
        $summary = (object) [
            'free' => 0, 'sold' => 0, 'booked' => 0, 'broken' => 0
        ];
        $apartments = Apartment::all()->map(function (Apartment $apartment) use (&$summary) {
            $diff = $apartment->updateFromArray($this->fetchModelFromUrl($apartment->url));
            $apartment->diff = $diff;
            switch ($apartment->state) {
                case 'Бронь':
                    $summary->booked += 1;
                    break;
                case 'свободна':
                    $summary->free += 1;
                    break;
                case 'Продана':
                    $summary->sold += 1;
                    break;
                default:
                    $summary->broken += 1;
            }
            return $apartment;
        });
        Mail::to('ikoolik@gmail.com')->cc('mrs.irina.kulikova@gmail.com')
            ->send(new Report(['apartments' => $apartments, 'summary' => $summary]));
    }
public function handle ( ) { $ summary = ( object ) [ 'free' => 0 , 'sold' => 0 , 'booked' => 0 , 'broken' => 0 ] ; $ apartments = Apartment :: all ( ) -> map ( function ( Apartment $ apartment ) use ( & $ summary ) { $ diff = $ apartment -> updateFromArray ( $ this -> fetchModelFromUrl ( $ apartment -> url ) ) ; $ apartment -> diff = $ diff ; switch ( $ apartment -> state ) { case 'Бронь': $ summary -> booked += 1 ; break ; case 'свободна': $ summary -> free += 1 ; break ; case 'Продана': $ summary -> sold += 1 ; break ; default : $ summary -> broken += 1 ; } return $ apartment ; } ) ; Mail :: to ( 'ikoolik@gmail.com' ) -> cc ( 'mrs.irina.kulikova@gmail.com' ) -> send ( new Report ( [ 'apartments' => $ apartments , 'summary' => $ summary ] ) ) ; }
Execute the console command.
Execute the console command .