Last active
April 29, 2017 13:07
-
-
Save PoTHuYJoHN/870b4e99d042420c1ee09dcd9e96ecd8 to your computer and use it in GitHub Desktop.
Laravel query DB by month from related table and convert string value to date
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Find Landing pages where has fields with date value by month | |
* Date format is mm/dd/yyyy | |
*/ | |
$eventItemsIds = LandingPage::where('section', 'events_items')->whereHas('fields', function ($query) use($month,$year) { | |
$query->whereHas('texts', function($query) use($month,$year) { | |
$query->where(\DB::raw('MONTH(STR_TO_DATE(value, \'%m/%d/%Y\'))'), '=', $month) | |
->where(\DB::raw('YEAR(STR_TO_DATE(value, \'%m/%d/%Y\'))'), '=', $year); | |
}); | |
})->lists('id'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment