Slide 1

Slide 1 text

Laravel 7, 8 and Other Goodies Jus$n Yost Engineering Manager at Wirecu.er CC BY-NC 4.0 Jus-n Yost 1

Slide 2

Slide 2 text

Laravel • One of the most popular PHP Frameworks • Every 6 months a new major version is released (6 months ac?ve support, 12 months bug support) CC BY-NC 4.0 Jus-n Yost 2

Slide 3

Slide 3 text

Laravel 7 • Released in March of 2020 • Updates to Symfony 5 Packages • As usual a slew of new features and general improvements CC BY-NC 4.0 Jus-n Yost 3

Slide 4

Slide 4 text

Laravel Sanctum (not Airlock) • First Party API Authen1ca1on Package • Provides support for straigh:orward API authen1ca1on • If you need to provide a full OAuth 2 auth server, this isn't that • Not quite as secure but probably secure enough and faster to work with • No Client Creden1al or Authoriza1on Code Grant CC BY-NC 4.0 Jus-n Yost 4

Slide 5

Slide 5 text

Z"p HTTP Client • Z#p is a wrapper around Guzzle that minimizes the API and wraps it into a Laravel facade goodness Illuminate\Support\Facades\Http:: get($url, ['foo' => 'bar']); CC BY-NC 4.0 Jus-n Yost 5

Slide 6

Slide 6 text

Z"p • Biggest feature here (imo) is reducing the workload to mock a response Http::fake([ // Stub a JSON response for GitHub endpoints... 'github.com/*' => Http::response(['foo' => 'bar'], 200, ['Headers']), ]); CC BY-NC 4.0 Jus-n Yost 6

Slide 7

Slide 7 text

First Party CORS Solu1on • CORS configura/on file and basically done CC BY-NC 4.0 Jus-n Yost 7

Slide 8

Slide 8 text

Fluent String Opera/ons return (string) Str::of(' This is a string') ->trim() ->words(2, '...') ->upper(); // THIS IS ... CC BY-NC 4.0 Jus-n Yost 8

Slide 9

Slide 9 text

Custom Class-Based Blade Components • Class based rendering logic layer in Laravel • Uses the x- syntax • Public Proper:es are passed to the class • Can then modify and pass along data to a new Blade template CC BY-NC 4.0 Jus-n Yost 9

Slide 10

Slide 10 text

Custom Stubs for Ar-san Make php artisan stub:publish • Provides the common Laravel stubs that you can customize for your project next ;me you run artisan make CC BY-NC 4.0 Jus-n Yost 10

Slide 11

Slide 11 text

Mul$ple Mail Drivers • Same as DB Drivers, mul0ple ways to send out an email Mail::mailer('postmark') ->send(new TransactionEmail($transaction)); Mail::mailer('mailchimp') ->send(new WelcomeEmail($transaction)); CC BY-NC 4.0 Jus-n Yost 11

Slide 12

Slide 12 text

Rou$ng Improvements • Rou%ng, when cached, up to 2x faster than Laravel 6 • Model Binding to custom fields Route::get('users/{user:slug}', function (App\User $user) { return $user; }); CC BY-NC 4.0 Jus-n Yost 12

Slide 13

Slide 13 text

Custom Eloquent Casts at Query Time • withCasts lets you cast fields to a custom Laravel type when you run a query $users = User::select( [ 'users.*', 'last_posted_at' => PostForUser::select(['created_at'])->get(); ], ->withCasts(['last_posted_at' => 'date']) ->get(); CC BY-NC 4.0 Jus-n Yost 13

Slide 14

Slide 14 text

Laravel 8 • Released in September of 2020 CC BY-NC 4.0 Jus-n Yost 14

Slide 15

Slide 15 text

Model Changes • Adds a App\Model namespace • Model Factories now class based • Factories can add func7ons to do state transforma7on CC BY-NC 4.0 Jus-n Yost 15

Slide 16

Slide 16 text

Migra&on Squashing • Squashes all the migra0ons to a single schema file • Then the schema runs before any new migra0ons php artisan schema:dump php artisan schema:dump --prune CC BY-NC 4.0 Jus-n Yost 16

Slide 17

Slide 17 text

Job Batching $batch = \Illuminate\Support\Facades\Bus::batch([ new ProcessPodcast(Podcast::find(1)), new ProcessPodcast(Podcast::find(2)), ])->then(function (\Illuminate\Bus\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; CC BY-NC 4.0 Jus-n Yost 17

Slide 18

Slide 18 text

Rate Limi)ng • Rate Limi*ng is now a real rate limi*ng system • Rate Limi*ng can be defined based on the User, scale up and down, by IP CC BY-NC 4.0 Jus-n Yost 18

Slide 19

Slide 19 text

Maintenance Mode • Now just a token, no IP address bypass lis8ng • Set an error page to render before Laravel is available in maintenance mode php artisan down --secret="AllowMe" --render="errors::503" https://example.com/AllowMe CC BY-NC 4.0 Jus-n Yost 19

Slide 20

Slide 20 text

Time Tes'ng Improvements • Travel through .me $this->travel(5)->minutes(); $this->travelTo(now()->subHours(8)); $this->travelBack(); CC BY-NC 4.0 Jus-n Yost 20

Slide 21

Slide 21 text

Backoff Queued Jobs • Enable exponen,al backoff of queued jobs public function backoff() { return [1, 2, 5, 10, 30]; } CC BY-NC 4.0 Jus-n Yost 21

Slide 22

Slide 22 text

Laravel Jetstream • Applica(on scaffold for Laravel • Replaces the old Laravel auth scaffolding • Provides: login, registra(on, email verifica(on, 2FA, session, API and team management • Uses Tailwind for CSS • Uses Livewire or Iner(a.js for frontend rendering CC BY-NC 4.0 Jus-n Yost 22

Slide 23

Slide 23 text

Thanks Ques%ons? • twi%er.com/jus0nyost • github.com/jus0nyost • jus0nyost.com • lynda.com/jus0nyost CC BY-NC 4.0 Jus-n Yost 23