Questions tagged [laravel-helper]

Laravel includes a variety of global "helper" PHP functions. Many of these functions are used by the framework itself; however, you are free to use them in your own applications if you find them convenient.

Laravel provides many excellent helper functions that are convenient for doing things like working with arrays, file paths, strings, and routes, among other things like the beloved dd() function.

29 questions
600
votes
23 answers

How to create custom helper functions in Laravel

I would like to create helper functions to avoid repeating code between views in Laravel. For example: view.blade.php

Foo Formated text: {{ fooFormatText($text) }}

They're basically text formatting functions. How should I define globally…
Calebe Oliveira
  • 6,111
  • 3
  • 14
  • 7
154
votes
4 answers

Best Practices for Laravel 4 Helpers and Basic Functions?

I'm trying to understand the best place to put a global function in Laravel 4. For example, date formatting. I don't think making a facade is worth it as facades are too modular. I've read articles about creating a library folder and storing classes…
Jason Spick
  • 6,028
  • 13
  • 40
  • 59
84
votes
6 answers

"Call to undefined function str_slug()" in Laravel 6.0

I've upgraded my laravel 5.8 project to 6.0. It has upgraded successfully but when I'm trying to run the project or installing another package to my project it is giving me error named as "Call to undefined function str_slug()" in session.php. I…
Soft Technoes
  • 1,065
  • 1
  • 7
  • 18
40
votes
4 answers

After upgrading Laravel from 5.6 to 6.0, Call to undefined str_random() function not working

I have upgraded Laravel from 5.6 to 6.0. Previously, default helper functions were running fine on the controllers, but now it says "undefined." In my controller, I have used the following. $filename = str_random(12); I am getting the following…
8
votes
8 answers

Laravel: Set asset without protocol

Use asset helper function like below: will get Is there any laravel build-in solutions can let it…
Chen-Tsu Lin
  • 22,876
  • 16
  • 53
  • 63
3
votes
1 answer

Using Laravel helpers in package

I'm trying to write tests for my laravel package and it depends on Laravel helper dispatch. But package itself don't contains this function. So I have an error when run tests Is there a solution for this case? Or should I use DI and inject…
user11123107
2
votes
4 answers

How to add variables to request()->all()? (Laravel 6.0)

I have Laravel 6.0 with something like this using the request()->all(); helper to create a new row on the database... $input = request()->all(); Service::create($input); I want to add two variables to it manually so that we don't need the user to…
sdexp
  • 756
  • 4
  • 18
  • 36
2
votes
1 answer

Laravel URL helper: How to generate a perfect URL with query parameters and hash

Suppose the route is like this: Route::get('messages/{messages}', ['as' => 'messages.show', 'uses' => 'MessagesController@show']); So, when we will create an URL using URL helper of Laravel, {{ route('messages.show', 12) }} will display…
Debiprasad
  • 5,895
  • 16
  • 67
  • 95
1
vote
2 answers

Asset Helper Function Not Working Correctly in Laravel 5.7

I'm new to MVC and Laravel, and I'm trying to include CSS but getting a 404 error. The URL it's generating is... http://localhost/testing_laravel/css/app.css If I use the URL this way instead... http://localhost/testing_laravel/public/css/app.css…
Mohsin
  • 179
  • 4
  • 13
1
vote
2 answers

Creating a Helper Class for Laravel Artisan Command

I would like to know what's the best approach to create a helper class for my Artisan commands. I want the helper class to contain some static/non-static function to reduce code duplication as well as the size of my commands and to improve code…
Bahman.A
  • 1,166
  • 4
  • 18
  • 33
0
votes
1 answer

I got this error on laravel blade file -ErrorException A non well formed numeric value encountered on helper funtion

Form helper get string value. Then convert numeric value. Other helper functions work properly but only this portion doesn't work. if(isset($result[$product->id])){ $productArray[$product->id]+=…
0
votes
2 answers

How laravel's helper functions are available globally in every file?

I have just started exploring laravel but I have one confusion . I know how to create own custom function file and make it available globally using compose.json file but I was trying to figure out how laravel's helper function like route() , view()…
0
votes
1 answer

Guzzle calls in helper function randomly return 'magic request methods require a URI' error

My server is running on PHP 7.2 - Laravel 5.8 - Redis Jobs - NewRelic for monitoring configuration. The guzzle call is written inside helper function (that is autoloader from composer.json). The problem happens randomly. We get this…
0
votes
1 answer

how to load assets dynamically from resources folder to public folder and access them using asset() helper

I have just installed laravel 8.x and when I tried to get to the login page errors shows up regarding files loading such as CSS or js but only the ones that are located in the resources folder, some suggested copying them from the resources folder…
anouar es-sayid
  • 355
  • 5
  • 11
0
votes
1 answer

Laravel Helper to merge Period arrays

Laravel Version:7.0 I would like to know how to create this helper. Input is date range array. For example: $input1 = [2020-07-19, 2020-07-25]; $input2 = [2020-07-26, 2020-08-01]; $input3 = [2020-08-01, 2020-08-07]; $input4 = [2020-10-01,…
LoveCoding
  • 1,121
  • 2
  • 12
  • 33
1
2