Sunday, 5 December 2021

Laravel Call to undefined function App\str_random()

 Laravel is unable to find the method str_random.

Errors:

Call to undefined function App\str_random()

Call to undefined function App\\Models\\str_random()



Reason:

In the newer laravel version, laravel helpers have been moved to different namespaces.

and these helpers are separated in a package.


Solution:

To use these helpers we need to install a package using the following command.


composer require laravel/helpers


Old helpers will be installed and we can easily use them without any trouble.


Alternative solution:

In case you don't want to use any package for these older Laravel helpers then simply 

use these namespaces at the top of your file.

 

use Illuminate\Support\Arr classes.

user Illuminate\Support\Str


update newly defined methods for example 


 Str::random(60);


clear the views using the following command


php artisan view:clear



No comments:

Post a Comment

Laravel csrf token mismatch for ajax post request

Error "CSRF Token Mismatch" commonly occurs if tokens do not match in both sessions and sent , and received requests.CSRF token he...