mgsmus evet hocam css stilleride verdim fakat böyle
https://prnt.sc/UEZLx5s_aH7z
public $questionnaireId;
public function __construct($questionnaireId) {
$this->questionnaireId = $questionnaireId;
}
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
public function drawings()
{
$drawing = new Drawing();
$drawing->setHeight(90);
$drawing->setCoordinates('B3');
return $drawing;
}
public function view(): View
{
$surveys = DB::table('survey_responses')
->join('surveys', 'survey_responses.survey_id', '=', 'surveys.id')
->join('questions', 'survey_responses.questions_id', '=', 'questions.id')
->join('answers', 'survey_responses.answer_id', '=', 'answers.id')
->join('questionnaire', 'questions.questionnaire_id', '=', 'questionnaire.id')
->select(
'surveys.name as Survey Name',
'surveys.latitude as latitude',
'surveys.longitude as longitude',
'questions.question as Question',
'answers.answer as Answer',
'surveys.image as Image'
)
->where('questionnaire.id', $this->questionnaireId)
->get();
$surveyData = [];
foreach ($surveys as $survey) {
$surveyName = $survey->{'Survey Name'};
$question = $survey->Question;
$answer = $survey->Answer;
$image = $survey->Image;
$link = $survey->latitude.' '.$survey->longitude;
if (!isset($surveyData[$surveyName])) {
$surveyData[$surveyName] = [];
}
if (!isset($surveyData[$surveyName][$question])) {
$surveyData[$surveyName][$question] = [];
}
$surveyData[$surveyName][$question][] = [
'answer' => $answer,
'link' => $link,
'image' => $image,
];
}
return view('exports.surveys', [
'surveyData' => $surveyData
]);
}
<td class="image-cell">
@if ($i == 0 && isset($questionData[$question][$i]['image']))
<img src="{{ $questionData[$question][$i]['image'] }}" alt="Image" class="image-cell" />
@endif
</td>
Tümü
<table>
<thead>
<tr>
<th style="width: 150px;"></th>
@if (!empty($surveyData))
@foreach ($surveyData[array_key_first($surveyData)] as $question => $answers)
<th style="width: {{ strlen($question) * 6 }}px;">{{ $question }}</th>
@endforeach
<th class="image-cell">Image</th>
<th>Location</th>
@endif
</tr>
</thead>
<tbody>
@if (!empty($surveyData))
@foreach ($surveyData as $surveyName => $questionData)
@php
$maxAnswers = max(array_map('count', $questionData));
@endphp
@for ($i = 0; $i < $maxAnswers; $i++)
<tr>
<td>
@if ($i == 0)
{{ $surveyName }}
@endif
</td>
@foreach ($questionData as $question => $answers)
<td>
@if (isset($answers[$i]['answer']))
{{ $answers[$i]['answer'] }}
@endif
</td>
@endforeach
<td class="image-cell">
@if ($i == 0 && isset($questionData[$question][$i]['image']))
<img src="{{ $questionData[$question][$i]['image'] }}" alt="Image" class="image-cell" />
@endif
</td>
<td>
@if ($i == 0 && isset($questionData[$question][$i]['link']))
https://www.google.com/maps/place/{{ $questionData[$question][$i]['link'] }}
@endif
</td>
</tr>
@endfor
<tr></tr>
@endforeach
@endif
</tbody>
</table>