Using PHP functions in view

Posted 10 months ago by ochirach

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);

There are $number_of_weeks_in_current_month week(s) in this month

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

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.