{{-- This partial is included twice per row: 1) Once BEFORE the table (add modal) — $data = new Gallery() → no id 2) Once INSIDE @foreach (edit modal) — $data = the row model → has id All preview element IDs are suffixed with the record id (or "new") so multiple modals on the same page never share an id. --}} @php $isEdit = !empty($data->id); $suffix = $isEdit ? $data->id : 'new'; $modalId = $isEdit ? 'editRowModal' . $data->id : 'addRowModal'; // $data->image is an object (stdClass) because of the custom accessor $imageObj = $isEdit ? ($data->image ?? null) : null; $hasImg = $isEdit && $imageObj && (isset($imageObj->original) || isset($imageObj->video_id)); @endphp