{"id":34726,"date":"2022-04-13T04:08:03","date_gmt":"2022-04-13T04:08:03","guid":{"rendered":"https:\/\/www.globalizationpartners.com\/?p=34726"},"modified":"2022-04-14T07:02:55","modified_gmt":"2022-04-14T07:02:55","slug":"whats-new-in-laravel-9","status":"publish","type":"post","link":"https:\/\/www.globalizationpartners.com\/2022\/04\/13\/whats-new-in-laravel-9\/","title":{"rendered":"What&#8217;s new in Laravel 9"},"content":{"rendered":"<h2>What is Laravel?<\/h2>\n<p>Laravel is an open-source PHP framework for building full-stack web applications. Laravel is a framework not a CMS and it gives you full control over the application. Laravel takes care of a lot of the things that are hard to develop yourself such as routing, HTML templating, and authentication.<\/p>\n<p>&nbsp;<\/p>\n<h2>Why use Laravel and what are its features?<\/h2>\n<p><strong>1. Support and community<\/strong><br \/>\n<strong>2. Security<\/strong><br \/>\n<strong>3. Exceptional Support &amp; Performance Using MVC Architecture<\/strong><br \/>\n<strong>4. Database Interaction Made Simple with Eloquent ORM<\/strong><br \/>\n<strong>5. Artisan CLI For Extremely Easy &amp; Quick Commands<\/strong><br \/>\n<strong>6. A Template Engine for Exceptional Layouts<\/strong><br \/>\n<strong>7. Testing<\/strong><br \/>\n<strong>8. Automatic Pagination<\/strong><\/p>\n<p>&nbsp;<\/p>\n<h2>Laravel 9<\/h2>\n<p>It was initially scheduled to be released by September 2021, Laravel 9\u2019s release was pushed to January 2022 and was finally released on February 8th, 2022. Laravel 9 includes a minimum PHP 8.0 version, controller route groups, an updated default Ignition error page, Laravel Scout database engine, Symfony mailer integration, Flysystem 3.x, improved Eloquent accessors\/mutators, and many more features.<\/p>\n<p>&nbsp;<\/p>\n<h2>What\u2019s new in Laravel 9?<\/h2>\n<p><strong>1. Anonymous Stub Migrations<\/strong><\/p>\n<p>The main issue is that if many migrations have the same class name, it may cause problems when attempting to rebuild the database from scratch.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-34737 size-full\" src=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/whats-new-in-laravel-9-gpi-blog-1.png\" alt=\"Laravel 9 Setup Screen\" width=\"420\" height=\"368\" srcset=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/whats-new-in-laravel-9-gpi-blog-1.png 420w, https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/whats-new-in-laravel-9-gpi-blog-1-300x263.png 300w\" sizes=\"(max-width: 420px) 100vw, 420px\" \/><\/p>\n<p><strong>2. New Query Builder Interface<\/strong><\/p>\n<p>Laravel 9 has a new Query Builder Interface, which you can learn more about in this merged PR.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-34882 size-full\" src=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/New-Query-Builder-Interface-Laravel9.jpg\" alt=\"New Query Builder Interface - Laravel 9\" width=\"427\" height=\"224\" srcset=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/New-Query-Builder-Interface-Laravel9.jpg 427w, https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/New-Query-Builder-Interface-Laravel9-300x157.jpg 300w\" sizes=\"(max-width: 427px) 100vw, 427px\" \/><\/p>\n<p><strong>3. Laravel 9 requires PHP 8 as a minimum version.<\/strong><\/p>\n<p>Laravel 9 will need Symfony 6.0, which has a minimum requirement of PHP 8, implying that Laravel 9 would be restricted in the same way. Since Laravel 9 depends on PHP 8 Tom Schlick submitted a PR to move to using str_contains(), str_starts_with() and str_ends_with() functions internally in the \\Illuminate\\Support\\Str class.<\/p>\n<p><strong>4. New Design for (routes:list)<\/strong><\/p>\n<p>When using the (php artisan routes:list) command, if you have a large number of complicated routes specified, it might be difficult to examine them in the console.in Laravel 9 this command was changed for much more pretty.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-34888 size-full\" src=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/New-Design-for-route-list-Laravel9.jpg\" alt=\"New Design for (route:list) - Laravel 9\" width=\"562\" height=\"319\" srcset=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/New-Design-for-route-list-Laravel9.jpg 562w, https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/New-Design-for-route-list-Laravel9-300x170.jpg 300w\" sizes=\"(max-width: 562px) 100vw, 562px\" \/><\/p>\n<p><strong>5. New Test Coverage Option<\/strong><br \/>\nA new (php artisan test &#8211;coverage) command option will display the test coverage directly on the terminal.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-34893 size-full\" src=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/New-Test-Coverage-Option-Laravel9.jpg\" alt=\"New Test Coverage Option - Laravel 9\" width=\"563\" height=\"315\" srcset=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/New-Test-Coverage-Option-Laravel9.jpg 563w, https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/New-Test-Coverage-Option-Laravel9-300x168.jpg 300w\" sizes=\"(max-width: 563px) 100vw, 563px\" \/><\/p>\n<p><strong>6. From SwiftMailer to Symfony Mailer<\/strong><br \/>\nTo send outgoing emails, previous versions of Laravel used the Swift Mailer package. However, that library is no longer available and Symfony Mailer has taken its place. To discover more about Symfony Mailer check out this upgrade guide.<\/p>\n<p><strong>7. Laravel Scout Database Engine<\/strong><br \/>\nLaravel Scout originally launched with a focus on Algolia. However, since then several alternative &#8220;engines&#8221; have been introduced. As part of Laravel 9, for small to medium-sized applications, you may decide to leverage the new database engine.<\/p>\n<p><strong>8. Laravel Breeze API &amp; Next.js<\/strong><br \/>\nAn &#8220;API&#8221; scaffolding mode has been added to the Laravel Breeze starting kit as well as a companion Next.js frontend implementation. This starting kit scaffolding can be used to get your Laravel backend, Laravel Sanctum authenticated API, and JavaScript frontend up and running quickly.<\/p>\n<p><strong>9. Controller Route Groups<\/strong><\/p>\n<p>The controller method may now be used to establish a common controller for all the routes in the group. You simply need to supply the controller method that they invoke when establishing the routes:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-34898 size-full\" src=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/Controller-Route-Groups-Laravel9.jpg\" alt=\"Controller Route Groups - Laravel 9\" width=\"576\" height=\"171\" srcset=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/Controller-Route-Groups-Laravel9.jpg 576w, https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/Controller-Route-Groups-Laravel9-300x89.jpg 300w\" sizes=\"(max-width: 576px) 100vw, 576px\" \/><\/p>\n<p><strong>10. Bootstrap 5 Pagination Views<\/strong><\/p>\n<p>Pagination views developed with Bootstrap 5 are now included in Laravel. You may call the paginator&#8217;s useBootstrapFive function within the boot method of your App\\Providers\\AppServiceProvider: class to utilize these views instead of the default Tailwind views.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-34903 size-full\" src=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/Bootstrap-5-Pagination-Views-Laravel9.jpg\" alt=\"Bootstrap 5 Pagination Views - Laravel 9\" width=\"452\" height=\"281\" srcset=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/Bootstrap-5-Pagination-Views-Laravel9.jpg 452w, https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/Bootstrap-5-Pagination-Views-Laravel9-300x187.jpg 300w\" sizes=\"(max-width: 452px) 100vw, 452px\" \/><\/p>\n<p><strong>11. Enum Eloquent Attribute Casting<\/strong><\/p>\n<p>You may now cast your attribute values to PHP Enums in Eloquent. To do so, put the attribute and Enum you want to cast in the $casts property array of your model:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-34908 size-full\" src=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/Enum-Eloquent-Attribute-Casting-Laravel9.jpg\" alt=\"Enum Eloquent Attribute Casting - Laravel 9\" width=\"522\" height=\"262\" srcset=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/Enum-Eloquent-Attribute-Casting-Laravel9.jpg 522w, https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/Enum-Eloquent-Attribute-Casting-Laravel9-300x151.jpg 300w\" sizes=\"(max-width: 522px) 100vw, 522px\" \/><\/p>\n<p>When you interact with an attribute after you&#8217;ve declared the cast on your model, the provided attribute will be automatically cast to and from an Enum:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-34918 size-full\" src=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/Enum-Eloquent-Attribute-Casting.jpg\" alt=\"Enum Eloquent Attribute Casting\" width=\"490\" height=\"143\" srcset=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/Enum-Eloquent-Attribute-Casting.jpg 490w, https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/Enum-Eloquent-Attribute-Casting-300x88.jpg 300w\" sizes=\"(max-width: 490px) 100vw, 490px\" \/><\/p>\n<p><strong>12. Improved Ignition Exception Page<\/strong><\/p>\n<p>Spatie&#8217;s open-source exception debug page Ignition, has been completely redone from the bottom up. Light \/ dark themes, adjustable &#8220;open in editor&#8221; features, and more are included in the new, better Ignition that ships with Laravel 9.x .<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-34923 size-full\" src=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/Improved-Ignition-Exception-Page-Laravel9.jpg\" alt=\"Improved Ignition Exception Page - Laravel 9\" width=\"522\" height=\"333\" srcset=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/Improved-Ignition-Exception-Page-Laravel9.jpg 522w, https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/Improved-Ignition-Exception-Page-Laravel9-300x191.jpg 300w\" sizes=\"(max-width: 522px) 100vw, 522px\" \/><\/p>\n<p><strong>13. New Helpers<\/strong><br \/>\nLaravel 9.x includes two new, useful auxiliary methods that you may utilize in your own code.<br \/>\n(str)<br \/>\nThe str function returns a new Illuminate\\Support\\Stringable instance for the given string. This function is equivalent to the Str::of method:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-34928\" src=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/New-Helpers-Laravel9.jpg\" alt=\"New Helpers - Laravel 9\" width=\"515\" height=\"101\" srcset=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/New-Helpers-Laravel9.jpg 515w, https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/New-Helpers-Laravel9-300x59.jpg 300w\" sizes=\"(max-width: 515px) 100vw, 515px\" \/><\/p>\n<p>If the str function is used without an argument, it returns an instance of Illuminate\\Support\\Str:<\/p>\n<p>(to_route)<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-34933\" src=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/New-Helpers-to-route-Laravel9.jpg\" alt=\"New Helpers (to_route) - Laravel 9\" width=\"577\" height=\"72\" srcset=\"https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/New-Helpers-to-route-Laravel9.jpg 577w, https:\/\/www.globalizationpartners.com\/wp-content\/uploads\/2022\/03\/New-Helpers-to-route-Laravel9-300x37.jpg 300w\" sizes=\"(max-width: 577px) 100vw, 577px\" \/><\/p>\n<p>If necessary, you need to pass to HTTP status code that should be assigned to the redirect and any additional response headers as the third and fourth arguments to the to_route method:<\/p>\n<p><strong>14. The server.php file can be removed<\/strong><\/p>\n<p>It&#8217;s a little change, but you can now delete the server.php file from your project and the framework will still include it. Only php artisan serve makes use of this file.<\/p>\n<h2>Conclusion<\/h2>\n<p>Laravel 9 is now released, major updated versions will be released every 12 months and there will be more new features and announcements. We&#8217;ll keep this site updated when more details become available. You may also go to the official release website to learn more.<\/p>\n<p>&nbsp;<\/p>\n<h2>Resources<\/h2>\n<p><a href=\"https:\/\/laravel.com\/docs\/9.x\">https:\/\/laravel.com\/docs\/9.x<\/a><br \/>\n<a href=\"https:\/\/laravel-news.com\/laravel-9\">https:\/\/laravel-news.com\/laravel-9<\/a><br \/>\n<a href=\"https:\/\/laravel-news.com\/laravel-9-released\">https:\/\/laravel-news.com\/laravel-9-released<\/a><br \/>\n<a href=\"https:\/\/laracasts.com\/series\/whats-new-in-laravel-9\">https:\/\/laracasts.com\/series\/whats-new-in-laravel-9<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is Laravel? Laravel is an open-source PHP framework for building full-stack web applications. Laravel is a framework not a CMS and it gives you full control over the application. Laravel takes care of a lot of the things that are hard to develop yourself such as routing, HTML templating, and authentication. &nbsp; Why use [&hellip;]<\/p>\n","protected":false},"author":30,"featured_media":34913,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[1782,64],"_links":{"self":[{"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/posts\/34726"}],"collection":[{"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/users\/30"}],"replies":[{"embeddable":true,"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/comments?post=34726"}],"version-history":[{"count":11,"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/posts\/34726\/revisions"}],"predecessor-version":[{"id":34944,"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/posts\/34726\/revisions\/34944"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/media\/34913"}],"wp:attachment":[{"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/media?parent=34726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/categories?post=34726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globalizationpartners.com\/wp-json\/wp\/v2\/tags?post=34726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}