where('user_id', $user_id)->first(); $today = date('Y-m-d'); // 定期契約情報を取得(park/usertype/psection/ptypeテーブルもJOIN) $contracts = DB::table('regular_contract') ->join('park', 'regular_contract.park_id', '=', 'park.park_id') ->join('usertype', 'regular_contract.user_categoryid', '=', 'usertype.user_categoryid') ->leftJoin('city', 'park.city_id', '=', 'city.city_id') ->leftJoin('psection', 'regular_contract.psection_id', '=', 'psection.psection_id') ->leftJoin('ptype', 'regular_contract.ptype_id', '=', 'ptype.ptype_id') ->where('regular_contract.user_id', $user_id) ->where('regular_contract.contract_flag', 1) ->where('regular_contract.contract_cancel_flag', 0) ->where(function ($query) use ($today) { $query->where('regular_contract.contract_periode', '>', $today) ->orWhere(function ($q) use ($today) { $q->where('regular_contract.contract_periode', '<=', $today) ->whereRaw('DATEDIFF(?, regular_contract.contract_periode) <= 5', [$today]); }); }) ->select( 'regular_contract.contract_id', 'park.park_name', 'usertype.usertype_subject1', 'regular_contract.contract_periods', 'regular_contract.contract_periode', 'regular_contract.enable_months', 'regular_contract.contract_renewal', 'regular_contract.park_id', 'city.update_grace_period_start_date', 'city.update_grace_period_start_time', 'city.update_grace_period_end_date', 'city.update_grace_period_end_time', 'psection.psection_subject', 'ptype.ptype_subject', 'regular_contract.pplace_no' ) ->get(); // シール情報を取得 $seals = DB::table('regular_contract') ->join('usertype', 'regular_contract.user_categoryid', '=', 'usertype.user_categoryid') ->leftJoin('psection', 'regular_contract.psection_id', '=', 'psection.psection_id') ->leftJoin('ptype', 'regular_contract.ptype_id', '=', 'ptype.ptype_id') ->where('regular_contract.user_id', $user_id) ->where('regular_contract.contract_flag', 1) ->where('regular_contract.contract_cancel_flag', 0) ->where('regular_contract.contract_periode', '>=', $today) ->where('regular_contract.contract_permission', 1) ->select( 'regular_contract.contract_id', 'regular_contract.contract_qr_id', 'usertype.usertype_subject1', 'regular_contract.contract_periods', 'regular_contract.contract_periode', 'regular_contract.enable_months', 'regular_contract.contract_renewal', 'regular_contract.park_id', 'psection.psection_subject', 'ptype.ptype_subject', 'regular_contract.pplace_no' ) ->get(); // お知らせ情報を取得 $informations= DB::table('user_information_history') ->where('user_id', $user_id) ->orderBy('user_information_history_id', 'desc') ->limit(3) ->get(); \Log::info('マイページにアクセス', [ 'user_id' => $user_id, ]); return view('mypage.index', [ 'active_menu' => 'SWO-4-1', // マイページメニューの選択状態用 'user_name' => $user->user_name, // ユーザー名(ヘッダー用) 'contracts' => $contracts, 'seals' => $seals, 'informations' => $informations ]); } }