@foreach ($product_houses as $product_house) @php $toArray = function ($value) use (&$toArray) { if ($value instanceof \Illuminate\Support\Collection || $value instanceof \Illuminate\Database\Eloquent\Collection) { $value = $value->toArray(); } if (is_string($value)) { $decoded = json_decode($value, true); if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) { $value = $decoded; } } if (is_array($value)) { foreach ($value as $k => $v) { if (is_array($v) || $v instanceof \Illuminate\Support\Collection || $v instanceof \Illuminate\Database\Eloquent\Collection) { $value[$k] = $toArray($v); } } } return $value; }; $raw = $product_house->getMetas(); $data = $toArray($raw); if (!is_array($data)) { $data = []; } $formatName = function ($value) { if ($value === null || $value === '') { return ''; } if (is_string($value)) { $decoded = json_decode($value, true); if (json_last_error() === JSON_ERROR_NONE && is_array($decoded)) { return collect($decoded)->map(function ($item) { if (is_array($item)) { return $item['name'] ?? ($item['value'] ?? ''); } return $item; })->filter(function ($v) { return $v !== null && $v !== ''; })->implode(', '); } return $value; } if (is_array($value) || $value instanceof \Illuminate\Support\Collection) { return collect($value)->map(function ($item) { if (is_array($item) || is_object($item)) { $item = (array) $item; return $item['name'] ?? ($item['value'] ?? ''); } return $item; })->filter(function ($v) { return $v !== null && $v !== ''; })->implode(', '); } return (string) $value; }; $val = function ($key, $default = '') use ($data) { if (!array_key_exists($key, $data)) { return $default; } $v = $data[$key]; if ($v === null || $v === '') { return $default; } return $v; }; $filled = function ($row, $keys) { if (!is_array($row)) { return false; } foreach ($keys as $key) { if (array_key_exists($key, $row) && $row[$key] !== null && $row[$key] !== '') { return true; } } return false; }; $resolveImage = function ($src) { if (!$src) { return null; } if (is_string($src) && (str_starts_with($src, 'http://') || str_starts_with($src, 'https://') || str_starts_with($src, 'data:'))) { return $src; } $src = (string) $src; if (file_exists($src)) { return $src; } $relative = ltrim($src, '/'); $candidates = [ public_path($relative), storage_path('app/public/' . $relative), storage_path('app/' . $relative), base_path('../filmfuse_admin/public/' . $relative), ]; foreach ($candidates as $candidate) { if (file_exists($candidate)) { return $candidate; } } return rtrim(config('app.url'), '/') . '/' . $relative; }; $keypeople = is_array($data['keypeople'] ?? null) ? $data['keypeople'] : []; $information = is_array($data['information'] ?? null) ? $data['information'] : []; $scenes = is_array($data['scenes'] ?? null) ? $data['scenes'] : []; $castmembers = is_array($data['castmembers'] ?? null) ? $data['castmembers'] : []; $crew = is_array($data['crew'] ?? null) ? $data['crew'] : []; $crewmembers = is_array($data['crewmembers'] ?? null) ? $data['crewmembers'] : []; $logoSrc = $resolveImage($val('logo')); if (!$logoSrc) { $defaultCandidates = [ public_path('safty-logo.png'), base_path('../filmfuse_admin/public/safty-logo.png'), '/var/www/adminnew/public/safty-logo.png', ]; foreach ($defaultCandidates as $candidate) { if (file_exists($candidate)) { $logoSrc = $candidate; break; } } } $productionTitle = $val('production_title', $val('file_title', 'Production Title')); $address = $val('address'); $mapSrc = null; if ($address !== '') { $mapKey = config('services.google.maps_key', 'AIzaSyCEFG4Q1HsFf0PqL5bNwmexarwksNuBFnw'); $mapSrc = 'https://maps.googleapis.com/maps/api/staticmap?' . http_build_query([ 'center' => $address, 'zoom' => 15, 'size' => '500x195', 'maptype' => 'roadmap', 'markers' => 'color:red|' . $address, 'key' => $mapKey, ]); } $castRows = []; foreach ($castmembers as $cast) { if ($filled($cast, ['cast', 'character', 'call_time', 'special_instructions'])) { $castRows[] = $cast; } } $crewRendered = 0; @endphp @if($val('file_title') !== '')
File Name
{{ $val('file_title') }}
@endif
{{-- HEADER: Company | Logo + Title | Info --}}
{{ $val('company_name', 'Production Company Name') }}
{{ $val('company_street') }}
{{ $val('company_city') }}
{{ $val('company_website') }}
{{ $val('company_phone') }}
@forelse ($keypeople as $kp) @if($filled($kp, ['title', 'name', 'phone'])) @endif @empty @endforelse
{{ $kp['title'] ?? '' }} {{ $formatName($kp['name'] ?? '') }} {{ $kp['phone'] ?? '' }}
Producer
Director
PM
@if($logoSrc) Logo @else
Logo
@endif
{{ $productionTitle }}
@forelse ($information as $info) @if($filled($info, ['title', 'value'])) @endif @empty @endforelse
{{ $info['title'] ?? '' }} {{ $info['value'] ?? '' }}
Breakfast
Lunch
Sunrise
Sunset
Weather
{{ $val('hospital_title', 'Nearest Hospital') }} {{ $val('hospital_line1') }}
{{ $val('hospital_line2') }}
{{ $val('hospital_line3') }}
{{-- MAP + CALL + NOTES --}}
{{ $address !== '' ? $address : 'Location Address' }}
@if($mapSrc) Map @else
Map / Address
@endif
CALL
{{ $val('call_time') }}
{{ $val('shoot_date') }}
{{ $val('main_notes') }}
{{-- SCENES --}}
Scenes
@php $sceneShown = 0; @endphp @foreach ($scenes as $scene) @if($filled($scene, ['number', 'set_name', 'character_number', 'day_or_night', 'pages', 'notes', 'description'])) @php $sceneShown++; @endphp @if(!empty($scene['description'])) @endif @endif @endforeach @if($sceneShown === 0) @endif
# Set / Location Char # D/N Pages Notes
{{ $scene['number'] ?? '' }} {{ $scene['set_name'] ?? '' }} {{ $scene['character_number'] ?? '' }} {{ $scene['day_or_night'] ?? '' }} {{ $scene['pages'] ?? '' }} {{ $scene['notes'] ?? '' }}
{{ $scene['description'] }}
Total Pages: {{ $val('scene_total_pages', '0') }}
{{-- CAST --}}
Cast
@forelse ($castRows as $i => $cast) @empty @endforelse
# Cast Character Call Time Special Instructions
{{ $i + 1 }} {{ $formatName($cast['cast'] ?? '') }} {{ $cast['character'] ?? '' }} {{ $cast['call_time'] ?? '' }} {{ $cast['special_instructions'] ?? '' }}
{{-- NOTES --}}
Notes
@if($val('notes') !== '')
{{ $val('notes') }}
@endif
{{ $val('notes_table_left') }} {{ $val('notes_table_right') }}
{{-- CREW --}}
Crew
@foreach ($crew as $dIdx => $dept) @php $deptName = is_array($dept) ? ($dept['name'] ?? '') : (string) $dept; $members = is_array($crewmembers[$dIdx] ?? null) ? $crewmembers[$dIdx] : []; $memberRows = []; foreach ($members as $m) { if ($filled($m, ['title', 'name', 'phone', 'email', 'call_time'])) { $memberRows[] = $m; } } @endphp @if(($deptName !== null && $deptName !== '') || count($memberRows) > 0) @php $crewRendered++; @endphp
{{ $deptName !== '' && $deptName !== null ? $deptName : 'Department' }}
@forelse ($memberRows as $member) @empty @endforelse
Title Name Phone Email Call
{{ $member['title'] ?? '' }} {{ $formatName($member['name'] ?? '') }} {{ $member['phone'] ?? '' }} {{ $member['email'] ?? '' }} {{ $member['call_time'] ?? '' }}
@endif @endforeach @if($crewRendered === 0)
@endif
@if (!$loop->last)
@endif @endforeach