Input for every day in the month:
I'm using PHP Laravel and I need to make dynamic inputs for every day of the month, like in the image. Any help is appreciated.
Input for every day in the month:
I'm using PHP Laravel and I need to make dynamic inputs for every day of the month, like in the image. Any help is appreciated.
Basically you're asking other people to write your code without even trying yourself, but here we go.
Laravel uses Carbon, a simple PHP API extension for PHP DateTime.
First you have to check which month you're currently in, and when you've done that, you can run the Carbon method called daysInMonth
on the Carbon instance to return the amount of days in the month of the current date.
use Carbon\Carbon;
$currentDate = Carbon::now();
$daysInMonth = $currentDate->daysInMonth);
return view('your.view', compact('daysInMonth');
Now you have the amount of days in the current month. Simple, just run a for loop while i
is equal or smaller than the $daysInMonth
.
That will look like the following:
@for($i = 1; $i =< $daysInMonth; $i++)
<input type="text" name="day[]" value="$i">
@endfor