What's new in Laravel 8



Hello habr! On the eve of the start of the "Framework Laravel" course , our expert and part-time active member of the Russian Laravel community - Vitaly Yushkevich, prepared an overview of new products in Laravel 8. I give the floor to Vitaly:



Hello!



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