2つのテーブルのデータを表示するAPIを作成しようとしていますが、この時点で固まっています。Api Laravelでのクエリ
これは私の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);
}
私は結果を取得しようとするたびに、それは常に私に0 = no data
を与えます
私を助けてもらえますか?
あなたはmysqlの上で、そのクエリを試してみましたか?なぜあなたは 'CONCAT()'を使っていますか? – phaberest
私はconcatを使って私の写真にURLを与えます –
またはあなたにはsoutionがありますか?私のために ? –