Hi @ochirach
It's better to use Carbon for date and time operations in laravel.
You can check this, you will find the answer.
You can use directly in laravel controller by simply doing this,
use Carbon\Carbon;
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I have a php function (named 'weeks_in_month') that calculates and returns the number of weeks in a month (parameters: month,year). I want to use this functions result within the view i.e
$number_of_weeks_in_current_month = weeks_in_month($current_month_number, $current_year);
How can I go about this? Is a new controller needed for this? or is this a job for Service Injection? This views controller currently has the 1 function to return the view from a get request.
I will want to store globally used functions like these within a single file for future use
If you're wanting to call the function from your blade file that would only be possible if it's a global helper. This article explains how to do that: https://stackoverflow.com/questions/32419619/how-do-i-make-global-helper-functions-in-laravel-5
The other option is to transform the data and send it to the view as a separate parameter.
Please or to participate in this conversation.