저는 Laravel의 초보자입니다. 그래서 모든 것이 탐사 기간에 있습니다. 나는 내가 $ 요청이 정의되어있어laravel 요청은 정의되지 않았습니다.
$request->input('key')
를 사용하는 경우 나, 그러나
dd($request)
Request {#40
#json: ParameterBag {#32
#parameters: array:4 [
"GPTour_id" => 1
"customer_id" => 1
"status" => "Confirmed"
"note" => "asdfasdf"
]
}
#userResolver: Closure {#300
class: "Illuminate\Auth\AuthServiceProvider"
this: AuthServiceProvider {#22 …}
use: array:1 [
"$app" => Application {#3
#basePath: "/Users/haophung/Dropbox/server/websites/nglaravelyep/laravel-backend"
#hasBeenBootstrapped: true
#booted: true
#bootingCallbacks: []
수 있어요 laravel에 걸쳐 및 laravel 컨트롤러에 데이터를 전송하기 위해 각 HTTP 포스트를 사용합니다. 제발 조언! GospelController.php 라인 (60)에
public function addGospelCustomer(Request $request)
{
if ($request) {
$customer_id = $request->get('customer_id');
$tour_id = $request->get('GPTour_id');
$validator = Validator::make($request->all(), [
'customer_id' =>'required'
]);
if ($validator->fails()) {
return response()->json(['error' => $validator->errors()], 406);
}
$gospel_customer = Gospel_tour::find($tour_id)->with(['customers' => function($query) {
$query->where('id', $customer_id);
}])->first();
if ($gospel_customer === 'null') {
return response()->json(['error' => "The Customer is already on the list"], 406);
}
return 'success';//response()->json(['success' => $request], 200);
}else {
return response()->json(['error' =>'can not add customer'], 401);
}
}
ErrorException : 정의되지 않은 변수는 : 나는 문제가
$gospel_customer = Gospel_tour::find($tour_id)->with(['customers' => function($query) {
$query->where('id', $customer_id);
}])->first();
내가 $ 밖으로 CUSTOMER_ID 에코 할 수있다 생각하지만,이 웅변에 정의되지 않은
을 CUSTOMER_ID
'$ request-> get ("key"); ' 어때요? –
내 업데이트를 확인하여 오류를 수정하십시오. i dd ($ request-> get ('key'))에 값이있는 경우'use ($ customer_id)' – EddyTheDove
을 추가해야합니다. var에 할당 된 경우 왜 작동하지 않는지 모르겠습니다 .. –