Novedades de Laravel 8



¡Hola habr! La víspera del inicio del curso "Framework Laravel" , nuestro experto y miembro activo a tiempo parcial de la comunidad rusa de Laravel, Vitaly Yushkevich, preparó una descripción general de los nuevos productos en Laravel 8. Le doy la palabra a Vitaly:



¡Hola!



Laravel 8 . , ; , " ". , - Laravel, ui preset .



, laravel .






Laravel .



laravel https://github.com/laravel/installer. , composer.json. :



~/.composer/composer.json. 


laravel 8:



"laravel/installer": "^4.0".


:



composer global update 


.



:



--jet             Installs the Laravel Jetstream scaffolding


, .



laravel 8 php 7.3. https://laravel.com/docs/8.x/installation#server-requirements







, - Models namespace (App\Models).



make:model. Models, php artisan make:model ModelName Models namespace (App\Models). , app namespace App. , .



Migration Squashing



. , , .



Laravel 8 schema:dump, schema. —prune, . , .



Model Factory Classes



. Model factory — , factory() (* HasFactory).



. , make() create() . ,



User::factory()->active()->subscribed()->client()->make()


. 2 : has for. , 5 , :



User::factory()->has(Post::factory()->count(5))->create()
 ""    
User::factory()->hasPosts(5)->create()


for() BelongsTo



Maintenance Mode



php artisan down :



--redirect[=REDIRECT]  The path that users should be redirected to
--render[=RENDER]      The view that should be prerendered for display during maintenance mode
--retry[=RETRY]        The number of seconds after which the request may be retried
--secret[=SECRET]      The secret phrase that may be used to bypass maintenance mode
--status[=STATUS]      The status code that should be used when returning the maintenance mode response [default: "503"]


secret, :



php artisan down --secret=my_secret_down_key


mysite.com/my_secret_down_key, , ( ). maintenance .



render html . ( ), (—render="errors::503"). — composer update, . render 503 , html .



Closure-Based Event Listeners



Listeners . , ( , , ).



:



    :
Event::listen(MyEvent::class, function(MyEvent $event) {
    // do smth
})

   :
Event::listen(function(MyEvent $event) {
    // do smth
})

    queueable,      :
Event::listen(queueable(function(MyEvent $event) {
    // do smth
}))


Time Testing helper



Wormhole, , " ", . ( , — ) , .



:



public function testTimeCanBeManipulated()
{
    // Travel into the future...
    $this->travel(5)->milliseconds();
    $this->travel(5)->seconds();
    $this->travel(5)->minutes();
    $this->travel(5)->hours();
    $this->travel(5)->days();
    $this->travel(5)->weeks();
    $this->travel(5)->years();

    // Travel into the past...
    $this->travel(-5)->hours();

    // Travel to an explicit time...
    $this->travelTo(now()->subHours(6));

    // Return back to the present time...
    $this->travelBack();
}


rate-limit



rate limit middleware. 8 rate limit RouteServiceProvider . . midleware rate limit, ip (, ).



JetStream frontend



UI, blade. , . . , .



Job batching



Bus batch() . . :



use App\Jobs\ProcessPodcast;
use App\Podcast;
use Illuminate\Bus\Batch;
use Illuminate\Support\Facades\Bus;
use Throwable;

$batch = Bus::batch([
    new ProcessPodcast(Podcast::find(1)),
    new ProcessPodcast(Podcast::find(2)),
    new ProcessPodcast(Podcast::find(3)),
    new ProcessPodcast(Podcast::find(4)),
    new ProcessPodcast(Podcast::find(5)),
])->then(function (Batch $batch) {
    // All jobs completed successfully...
})->catch(function (Batch $batch, Throwable $e) {
    // First batch job failure detected...
})->finally(function (Batch $batch) {
    // The batch has finished executing...
})->dispatch();

return $batch->id;




closure job dispatch, artisan serve, Routing Namespace . changelog . https://laravel.com/docs/8.x/releases :)





, . , , Laravel. frontend , "" ui . Taylor , . Taylor ? laravel ? .



. , , .




All Articles