2017-07-05 43 views
1

我使用碳比較2個日期與今天的日期,但是我也有包含了像值的數據庫稱爲平日另一個領域:Laravel碳,檢索今天的日期與工作日?

「MO」 「TU」 「WE」

所以我不只想搜索和按日期輸出也由平日所以搜索:

public function show($id) 
{ 
    $today = Carbon::now(); 
    $weekday = //whatever carbon or something else has to retrieve today's day 
    $event = Event::with('businesses') 
     ->where('startdate', '<', $today->format('Y-m-d')) 
     ->where('endate', '>', $today->format('Y-m-d')) 
     //or where ('weekday') = $weekday? 
     ->get(); 
    return view('events.showEvent', compact('event')); 
} 

回答

1

我不知道碳具有這樣的格式,但你可以做的是從地圖獲得wekkday天和當前週日常數:

$weekMap = [ 
    0 => 'SU', 
    1 => 'MO', 
    2 => 'TU', 
    3 => 'WE', 
    4 => 'TH', 
    5 => 'FR', 
    6 => 'SA', 
]; 
$dayOfTheWeek = Carbon::now()->dayOfWeek; 
$weekday = $weekMap[$dayOfTheWeek];