class AddSubmit extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('reserve_managements', function (Blueprint $table) {
$table->boolean('lodging');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('reserve_managements', function (Blueprint $table) {
$table->dropColumn('lodging');
});
}
}
/**
* 月毎に集計する
*/
public function countByMonthly()
{
return ReserveDayList::select(DB::raw('DATE_FORMAT(day, "%Y-%m") as yearmonth'), DB::raw('count(*) as count'), DB::raw('count(*) * 2000 as total'))
->groupby('yearmonth')
->get();
}
/**
* indexの月別表示
*
* @return \Illuminate\Http\Response
*/
public function indexToMonthly(Request $request)
{
return redirect('management?year='.$request->year.'&month='.$request->month);
}
クエリパラメータ付きURLを作成し、リダイレクトを行っています。
これしか方法が思い浮かばなかった。
次はリポジトリ。
/**
* 月別予約一覧を取得する
*
* @return ReserveManagement[]
*/
public function getListByMonth($year, $month)
{
return ReserveManagement::where('start_day', '>=', date('Y-m-d', strtotime('first day of '.$year.'-'.$month)))
->where('start_day', '<=', date('Y-m-d', strtotime('last day of '.$year.'-'.$month)))
->get();
}