Я пытаюсь получить сбор данных из API RestFul, когда переменная $ response возвращает данные, все хорошо, но если нет, я столкнулся с проблемой, это мой код:
public function showAsStage($id)
{
try {
$notis = Notification::with('stage')->orderBy('created_at', 'desc')
->where('stage_id', $id)
->get();
if(!$notis->isEmpty()){
foreach($notis as $noti){
$json = $noti->file ? json_decode($noti->file) : '';
$file = $json ? (string)$json[0]->download_link : '';
$response[] = [
'id' => $noti->id ? $noti->id : '',
'body' => $noti->body ? $noti->body : '',
'stage' => $noti->stage->stage ? $noti->stage->stage : '',
'time' => $noti->created_at ? $noti->created_at : '',
'course' => "عام",
'image' => $noti->file ?'http://172.18.23.41:8000/storage/'.$file : null
];
}
}
}catch(\Exception $e){
return $this->sendError('Server Error.', $e->getMessage());
}finally{
return $this->sendResponse($response, 'Successfully fetch noti meta data');
}
}
когданет данных:
"Undefined variable: response"