<?php

namespace App\Http\Controllers;

use App\Models\BoardingPass;
use App\Models\Cruise;
use Illuminate\Http\Request;

class CheckOutController extends Controller
{

    public function checkOut(Request $request, Cruise $cruise)
    {
        $boardingPasses  = BoardingPass::with(['ticket.segment' => function ($query) use ($cruise) {
            $query->where('cruise_id', $cruise->id);
        }])->get();
        foreach($boardingPasses as $boardingPass){
            $boardingPass->checked_out_at = now();
            $boardingPass->save();
        }
        
        return redirect()->route('cruises.index')->with('status', 'checked out updated!');
    }
}
