Laravel foreach month start from current monthDeleting an element from an array in PHPHow do I organise a PHP foreach loop by the filename it spits out?How does PHP 'foreach' actually work?php - for loop for each month of year3rd Last Day of the Month using PHP gmdate()Data visible only during date rangeWhy this list just go up to september?Output every month in a year in foreach loop PHPMysql date range query only check date without check month and yearAfter parsing month list sequence get changed
antimatter annihilation in stars
Complex conjugate and transpose "with respect to a basis"
Contour plot of a sequence of spheres with increasing radius
Is mountain bike good for long distances?
Strategies for dealing with chess burnout?
How to finish my PhD?
I multiply the source, you (probably) multiply the output!
Is it right to use the ideas of non-winning designers in a design contest?
I won a car in a poker game. How is that taxed in Canada?
Get Emacs to jump to the start of a word after isearch
Do you need to burn fuel between gravity assists?
How can I hint that my character isn't real?
Are professors obligated to accept supervisory role? If not, how does it work?
Did "Dirty Harry" feel lucky?
What can we do about our 9-month-old putting fingers down his throat?
Schrodinger's Cat Isn't Meant To Be Taken Seriously, Right?
Can you pop microwave popcorn on a stove?
How do you say "to hell with everything" in French?
Owner keeps cutting corners and poaching workers for his other company
Why does 8 bit truecolor use only 2 bits for blue?
How to plot two curves with the same area under?
PWM on 5V GPIO pin
Creating Chessboard with Javascript
If every star in the universe except the Sun were destroyed, would we die?
Laravel foreach month start from current month
Deleting an element from an array in PHPHow do I organise a PHP foreach loop by the filename it spits out?How does PHP 'foreach' actually work?php - for loop for each month of year3rd Last Day of the Month using PHP gmdate()Data visible only during date rangeWhy this list just go up to september?Output every month in a year in foreach loop PHPMysql date range query only check date without check month and yearAfter parsing month list sequence get changed
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have some data having date field. I want to display the data starting from the current month data ...
I get the 1st record started from current month. But next month is again starting from january. I want the records like current month+1 then currentmonth+2 and so on
@foreach($leave_manages as $holiday)
<tr>
<td class="danger">$holiday->date->format('F')</td>
<td class="warning">$holiday->date->format('d-m-Y')</td>
<td class="danger">$holiday->holiday</td>
<td class="info">$holiday->date->format('l')</td>
</tr>
@endforeach
Expected Result: March, April, May, June,............., February.
Actual Result: March, January, February..........,December
php laravel
add a comment |
I have some data having date field. I want to display the data starting from the current month data ...
I get the 1st record started from current month. But next month is again starting from january. I want the records like current month+1 then currentmonth+2 and so on
@foreach($leave_manages as $holiday)
<tr>
<td class="danger">$holiday->date->format('F')</td>
<td class="warning">$holiday->date->format('d-m-Y')</td>
<td class="danger">$holiday->holiday</td>
<td class="info">$holiday->date->format('l')</td>
</tr>
@endforeach
Expected Result: March, April, May, June,............., February.
Actual Result: March, January, February..........,December
php laravel
Can you post where the $leave_manages variable comes from. It looks like the issue is happening when you fetch this/set this variable.
– Ken
Mar 28 at 6:28
$leave_manages=Leave_manage::orderByRaw( "case when MONTH(date)=MONTH(CURDATE()) then MONTHNAME(date) end desc, MONTH(date) asc" )->get();
– Arora
Mar 28 at 6:32
Please can you show the how you're defining$leave_manages
i.e. the code in your controller and/or route
– Rwd
Mar 28 at 7:21
add a comment |
I have some data having date field. I want to display the data starting from the current month data ...
I get the 1st record started from current month. But next month is again starting from january. I want the records like current month+1 then currentmonth+2 and so on
@foreach($leave_manages as $holiday)
<tr>
<td class="danger">$holiday->date->format('F')</td>
<td class="warning">$holiday->date->format('d-m-Y')</td>
<td class="danger">$holiday->holiday</td>
<td class="info">$holiday->date->format('l')</td>
</tr>
@endforeach
Expected Result: March, April, May, June,............., February.
Actual Result: March, January, February..........,December
php laravel
I have some data having date field. I want to display the data starting from the current month data ...
I get the 1st record started from current month. But next month is again starting from january. I want the records like current month+1 then currentmonth+2 and so on
@foreach($leave_manages as $holiday)
<tr>
<td class="danger">$holiday->date->format('F')</td>
<td class="warning">$holiday->date->format('d-m-Y')</td>
<td class="danger">$holiday->holiday</td>
<td class="info">$holiday->date->format('l')</td>
</tr>
@endforeach
Expected Result: March, April, May, June,............., February.
Actual Result: March, January, February..........,December
php laravel
php laravel
edited Mar 28 at 7:19
Rwd
20.3k3 gold badges34 silver badges48 bronze badges
20.3k3 gold badges34 silver badges48 bronze badges
asked Mar 28 at 6:18
AroraArora
112 bronze badges
112 bronze badges
Can you post where the $leave_manages variable comes from. It looks like the issue is happening when you fetch this/set this variable.
– Ken
Mar 28 at 6:28
$leave_manages=Leave_manage::orderByRaw( "case when MONTH(date)=MONTH(CURDATE()) then MONTHNAME(date) end desc, MONTH(date) asc" )->get();
– Arora
Mar 28 at 6:32
Please can you show the how you're defining$leave_manages
i.e. the code in your controller and/or route
– Rwd
Mar 28 at 7:21
add a comment |
Can you post where the $leave_manages variable comes from. It looks like the issue is happening when you fetch this/set this variable.
– Ken
Mar 28 at 6:28
$leave_manages=Leave_manage::orderByRaw( "case when MONTH(date)=MONTH(CURDATE()) then MONTHNAME(date) end desc, MONTH(date) asc" )->get();
– Arora
Mar 28 at 6:32
Please can you show the how you're defining$leave_manages
i.e. the code in your controller and/or route
– Rwd
Mar 28 at 7:21
Can you post where the $leave_manages variable comes from. It looks like the issue is happening when you fetch this/set this variable.
– Ken
Mar 28 at 6:28
Can you post where the $leave_manages variable comes from. It looks like the issue is happening when you fetch this/set this variable.
– Ken
Mar 28 at 6:28
$leave_manages=Leave_manage::orderByRaw( "case when MONTH(date)=MONTH(CURDATE()) then MONTHNAME(date) end desc, MONTH(date) asc" )->get();
– Arora
Mar 28 at 6:32
$leave_manages=Leave_manage::orderByRaw( "case when MONTH(date)=MONTH(CURDATE()) then MONTHNAME(date) end desc, MONTH(date) asc" )->get();
– Arora
Mar 28 at 6:32
Please can you show the how you're defining
$leave_manages
i.e. the code in your controller and/or route– Rwd
Mar 28 at 7:21
Please can you show the how you're defining
$leave_manages
i.e. the code in your controller and/or route– Rwd
Mar 28 at 7:21
add a comment |
3 Answers
3
active
oldest
votes
Laravel provides built-in functions to get records using date functions. below code will get records from latest to older within the current year. user this
$leave_manages = $leave_manages = Leave_manage::whereYear('created_at', date('Y'))->orderBy('created_at', 'desc')->get();;
add a comment |
Since don't know the full content of your database not completely sure this is what you are looking for.
Assuming leave_manages table contains all the months you can use native eloquent query to fetch the results
$leave_manages = Leave_manage::whereDate('holiday', '>', CarbonCarbon::createFromDate(date('Y'), 1, 1))
->whereDate('holiday', '<', now())
->orderBy('holiday', 'acs')
->get();
$leave_manages->concact(Leave_manage::whereDate('holiday', '>', now())
->whereDate('holiday', '<', CarbonCarbon::createFromDate(date('Y'), 12, 31))
->orderBy('holiday', 'acs')
->get());
leave_manages table has a 'date' and a 'holiday' column.. I want to display the holiday starting from the current month
– Arora
Mar 28 at 7:04
Updated the answer
– Ken
Mar 28 at 7:09
thanks a lot..but january and february records are not showing.. records displayed from march to december
– Arora
Mar 28 at 7:18
Trynow()->addYear()
instead ofaddMonths(12)
(updated answer)
– Ken
Mar 28 at 7:23
I tried this code. Din't work
– Arora
Mar 28 at 7:27
|
show 8 more comments
$from = Carbon::now()->toDateTimeString();
$to = Carbon::now()->subMonth(11)->toDateTimeString();
$data = Leave_manage::where('created_at', '>=', $to)->where('created_at', '<=', $from)
->select(DB::raw("DATE_FORMAT(created_at, '%m') as login_month , DATE_FORMAT(created_at, '%Y') as login_year"))
->groupBy('login_month')
->groupBy('login_year')
->orderBy('login_year')
->orderBy('login_month')
->get();
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391234%2flaravel-foreach-month-start-from-current-month%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Laravel provides built-in functions to get records using date functions. below code will get records from latest to older within the current year. user this
$leave_manages = $leave_manages = Leave_manage::whereYear('created_at', date('Y'))->orderBy('created_at', 'desc')->get();;
add a comment |
Laravel provides built-in functions to get records using date functions. below code will get records from latest to older within the current year. user this
$leave_manages = $leave_manages = Leave_manage::whereYear('created_at', date('Y'))->orderBy('created_at', 'desc')->get();;
add a comment |
Laravel provides built-in functions to get records using date functions. below code will get records from latest to older within the current year. user this
$leave_manages = $leave_manages = Leave_manage::whereYear('created_at', date('Y'))->orderBy('created_at', 'desc')->get();;
Laravel provides built-in functions to get records using date functions. below code will get records from latest to older within the current year. user this
$leave_manages = $leave_manages = Leave_manage::whereYear('created_at', date('Y'))->orderBy('created_at', 'desc')->get();;
edited Mar 28 at 7:39
answered Mar 28 at 7:28
Adnan RasheedAdnan Rasheed
3744 silver badges6 bronze badges
3744 silver badges6 bronze badges
add a comment |
add a comment |
Since don't know the full content of your database not completely sure this is what you are looking for.
Assuming leave_manages table contains all the months you can use native eloquent query to fetch the results
$leave_manages = Leave_manage::whereDate('holiday', '>', CarbonCarbon::createFromDate(date('Y'), 1, 1))
->whereDate('holiday', '<', now())
->orderBy('holiday', 'acs')
->get();
$leave_manages->concact(Leave_manage::whereDate('holiday', '>', now())
->whereDate('holiday', '<', CarbonCarbon::createFromDate(date('Y'), 12, 31))
->orderBy('holiday', 'acs')
->get());
leave_manages table has a 'date' and a 'holiday' column.. I want to display the holiday starting from the current month
– Arora
Mar 28 at 7:04
Updated the answer
– Ken
Mar 28 at 7:09
thanks a lot..but january and february records are not showing.. records displayed from march to december
– Arora
Mar 28 at 7:18
Trynow()->addYear()
instead ofaddMonths(12)
(updated answer)
– Ken
Mar 28 at 7:23
I tried this code. Din't work
– Arora
Mar 28 at 7:27
|
show 8 more comments
Since don't know the full content of your database not completely sure this is what you are looking for.
Assuming leave_manages table contains all the months you can use native eloquent query to fetch the results
$leave_manages = Leave_manage::whereDate('holiday', '>', CarbonCarbon::createFromDate(date('Y'), 1, 1))
->whereDate('holiday', '<', now())
->orderBy('holiday', 'acs')
->get();
$leave_manages->concact(Leave_manage::whereDate('holiday', '>', now())
->whereDate('holiday', '<', CarbonCarbon::createFromDate(date('Y'), 12, 31))
->orderBy('holiday', 'acs')
->get());
leave_manages table has a 'date' and a 'holiday' column.. I want to display the holiday starting from the current month
– Arora
Mar 28 at 7:04
Updated the answer
– Ken
Mar 28 at 7:09
thanks a lot..but january and february records are not showing.. records displayed from march to december
– Arora
Mar 28 at 7:18
Trynow()->addYear()
instead ofaddMonths(12)
(updated answer)
– Ken
Mar 28 at 7:23
I tried this code. Din't work
– Arora
Mar 28 at 7:27
|
show 8 more comments
Since don't know the full content of your database not completely sure this is what you are looking for.
Assuming leave_manages table contains all the months you can use native eloquent query to fetch the results
$leave_manages = Leave_manage::whereDate('holiday', '>', CarbonCarbon::createFromDate(date('Y'), 1, 1))
->whereDate('holiday', '<', now())
->orderBy('holiday', 'acs')
->get();
$leave_manages->concact(Leave_manage::whereDate('holiday', '>', now())
->whereDate('holiday', '<', CarbonCarbon::createFromDate(date('Y'), 12, 31))
->orderBy('holiday', 'acs')
->get());
Since don't know the full content of your database not completely sure this is what you are looking for.
Assuming leave_manages table contains all the months you can use native eloquent query to fetch the results
$leave_manages = Leave_manage::whereDate('holiday', '>', CarbonCarbon::createFromDate(date('Y'), 1, 1))
->whereDate('holiday', '<', now())
->orderBy('holiday', 'acs')
->get();
$leave_manages->concact(Leave_manage::whereDate('holiday', '>', now())
->whereDate('holiday', '<', CarbonCarbon::createFromDate(date('Y'), 12, 31))
->orderBy('holiday', 'acs')
->get());
edited Mar 28 at 7:56
answered Mar 28 at 6:42
KenKen
1,2893 gold badges19 silver badges28 bronze badges
1,2893 gold badges19 silver badges28 bronze badges
leave_manages table has a 'date' and a 'holiday' column.. I want to display the holiday starting from the current month
– Arora
Mar 28 at 7:04
Updated the answer
– Ken
Mar 28 at 7:09
thanks a lot..but january and february records are not showing.. records displayed from march to december
– Arora
Mar 28 at 7:18
Trynow()->addYear()
instead ofaddMonths(12)
(updated answer)
– Ken
Mar 28 at 7:23
I tried this code. Din't work
– Arora
Mar 28 at 7:27
|
show 8 more comments
leave_manages table has a 'date' and a 'holiday' column.. I want to display the holiday starting from the current month
– Arora
Mar 28 at 7:04
Updated the answer
– Ken
Mar 28 at 7:09
thanks a lot..but january and february records are not showing.. records displayed from march to december
– Arora
Mar 28 at 7:18
Trynow()->addYear()
instead ofaddMonths(12)
(updated answer)
– Ken
Mar 28 at 7:23
I tried this code. Din't work
– Arora
Mar 28 at 7:27
leave_manages table has a 'date' and a 'holiday' column.. I want to display the holiday starting from the current month
– Arora
Mar 28 at 7:04
leave_manages table has a 'date' and a 'holiday' column.. I want to display the holiday starting from the current month
– Arora
Mar 28 at 7:04
Updated the answer
– Ken
Mar 28 at 7:09
Updated the answer
– Ken
Mar 28 at 7:09
thanks a lot..but january and february records are not showing.. records displayed from march to december
– Arora
Mar 28 at 7:18
thanks a lot..but january and february records are not showing.. records displayed from march to december
– Arora
Mar 28 at 7:18
Try
now()->addYear()
instead of addMonths(12)
(updated answer)– Ken
Mar 28 at 7:23
Try
now()->addYear()
instead of addMonths(12)
(updated answer)– Ken
Mar 28 at 7:23
I tried this code. Din't work
– Arora
Mar 28 at 7:27
I tried this code. Din't work
– Arora
Mar 28 at 7:27
|
show 8 more comments
$from = Carbon::now()->toDateTimeString();
$to = Carbon::now()->subMonth(11)->toDateTimeString();
$data = Leave_manage::where('created_at', '>=', $to)->where('created_at', '<=', $from)
->select(DB::raw("DATE_FORMAT(created_at, '%m') as login_month , DATE_FORMAT(created_at, '%Y') as login_year"))
->groupBy('login_month')
->groupBy('login_year')
->orderBy('login_year')
->orderBy('login_month')
->get();
add a comment |
$from = Carbon::now()->toDateTimeString();
$to = Carbon::now()->subMonth(11)->toDateTimeString();
$data = Leave_manage::where('created_at', '>=', $to)->where('created_at', '<=', $from)
->select(DB::raw("DATE_FORMAT(created_at, '%m') as login_month , DATE_FORMAT(created_at, '%Y') as login_year"))
->groupBy('login_month')
->groupBy('login_year')
->orderBy('login_year')
->orderBy('login_month')
->get();
add a comment |
$from = Carbon::now()->toDateTimeString();
$to = Carbon::now()->subMonth(11)->toDateTimeString();
$data = Leave_manage::where('created_at', '>=', $to)->where('created_at', '<=', $from)
->select(DB::raw("DATE_FORMAT(created_at, '%m') as login_month , DATE_FORMAT(created_at, '%Y') as login_year"))
->groupBy('login_month')
->groupBy('login_year')
->orderBy('login_year')
->orderBy('login_month')
->get();
$from = Carbon::now()->toDateTimeString();
$to = Carbon::now()->subMonth(11)->toDateTimeString();
$data = Leave_manage::where('created_at', '>=', $to)->where('created_at', '<=', $from)
->select(DB::raw("DATE_FORMAT(created_at, '%m') as login_month , DATE_FORMAT(created_at, '%Y') as login_year"))
->groupBy('login_month')
->groupBy('login_year')
->orderBy('login_year')
->orderBy('login_month')
->get();
edited Mar 28 at 11:59
answered Mar 28 at 11:48
ManishaManisha
748 bronze badges
748 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391234%2flaravel-foreach-month-start-from-current-month%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you post where the $leave_manages variable comes from. It looks like the issue is happening when you fetch this/set this variable.
– Ken
Mar 28 at 6:28
$leave_manages=Leave_manage::orderByRaw( "case when MONTH(date)=MONTH(CURDATE()) then MONTHNAME(date) end desc, MONTH(date) asc" )->get();
– Arora
Mar 28 at 6:32
Please can you show the how you're defining
$leave_manages
i.e. the code in your controller and/or route– Rwd
Mar 28 at 7:21