DEV Community

Cover image for Laravel 9: New Helpers!
Reza Khademi
Reza Khademi

Posted on

3

Laravel 9: New Helpers!

Soon, Laravel 9 wil release and there are some new features that we can use them.

This series is going to be a sequel about Laravel framework version 9 and in each article we will review a new feature!

1. str()

A new useful helper in Laravel 9 is str(). This function will return a new Stringable (Illuminate\Support\Stringable). We had this method on Str class and now it is more easier to use. eg:


$name = str('Reza')->append(' Khademi'); // 'Reza Khademi'

$snake = str()->snake('LaravelFramework'); // 'laravel_framework

Enter fullscreen mode Exit fullscreen mode

We should know, if no argument passed to this function it will give us a new instance of Illuminate\Support\Str.

2. to_route()

If we want to redirect user to a specific route, this will come handy:


return to_route(
   'users.show',
   ['user' => 1],
   302,
   ['X-Framework' => 'Laravel']
);

Enter fullscreen mode Exit fullscreen mode

we can pass the route name as the first, our desired data as the second and additional response headers as the third and fourth arguments to the to_route() method.

PHP 8 String Functions

Since PHP 8, str_contains(), str_starts_with() and str_ends_with() functions moved in to the \Illuminate\Support\Str class.

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay