I'm trying to make APIs showing data from two tables, but I'm stuck at this point.
This is my ApiController:
public function postDetaillog(Request $request)
{
$response = array();
$validator = Validator::make(
$request->all(),
[
'id'=> 'required',
]
);
if ($validator->fails()) {
$message = $validator->errors()->all();
$result['api_status'] = 0;
$result['api_message'] = implode(', ',$message);
$res = response()->json($result);
$res->send();
exit;
}
$data = DB::table('log_patrols')
->where('id', $request->input('id'))
->first();
$site = asset("uploads").'/';
$result = DB::table('log_patrol_details')
->select("*",DB::raw("concat('$site',photo1) as photo1"),DB::raw("concat('$site',photo2) as photo2"),DB::raw("concat('$site',photo3) as photo3"))
->where('id', $request->input('id'))
->first();
if (count($result) == 0) {
$response['api_status'] = count($result);
$response['api_message'] = "No data";
} else {
$response['api_status'] = 1;
$response['api_message'] = "success";
$response['data'] = $data;
$response['result'] = $result;
}
return response()->json($response);
}
Whenever I try to get the results, it always gives me 0 = no data
Could you please help me?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Tz42Zl
via IFTTT
Aucun commentaire:
Enregistrer un commentaire