Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why the Laravel helpers are deprecated in version 5.8?

I am a happy Laravel user and I love the Laravel helpers. They are very easy to use:

{{ str_limit($text) }}

But really really don't understand why this is they way:

{{\Illuminate\Support\Str::limit($text)}}

Why...?

like image 834
angelique000 Avatar asked Jul 01 '19 11:07

angelique000


People also ask

What is the use of helpers in Laravel?

What is a Helper Function? A helper function usually comes in handy if you want to add a feature to your Laravel application that can be used at multiple locations within your controllers, views, or model files. These functions can be considered as global functions.

What is difference between Laravel 8 and Laravel 9?

Laravel 9 provides New Query Builder Interface, making it easier for developers to work with. Laravel 9 has made some major improvements required in the Laravel 8, including Symfony 6.0 support. Flysystem 3.0 has improved more in comparison to previous versions.

What is the latest version of Laravel?

The latest Laravel version is version 9, which was released on February 8, 2022.


2 Answers

The reason for deprecating them in Laravel 5.8 being that they add a lot of fucntions to the global namespace and in addition to that they migth conflict withe packages as well. Taylor Otwell has said in the PR ,

  • https://techanical-atom.com/laravel-5-8-deprecate-arr-and-str-global-helper-methods/
like image 57
online Thomas Avatar answered Oct 11 '22 15:10

online Thomas


From the pull request:

They pollute the global namespace and they don't bring any additional value to the framework. They don't even save you the amount of characters that you have to type as in a bunch (or maybe in all?) of cases it's actually shorter to use the Arr and Str methods directly.

https://github.com/laravel/framework/pull/26898

If you still want to use them you can install the laravel/helpers package

like image 22
Thomas Avatar answered Oct 11 '22 14:10

Thomas