I am a newbie in Laravel, so everything is under exploration period. I use angular http post to send data over to laravel and in laravel controller i am able to
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: [] However, if i use
$request->input('key') i got $request is undefined. Please advise!!!
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 in GospelController.php line 60: Undefined variable: customer_id
I think the problem is
$gospel_customer = Gospel_tour::find($tour_id)->with(['customers' => function($query) { $query->where('id', $customer_id); }])->first(); I can echo $customer_id out, but in this eloquent is not defined
$request->get("key");how about?use($customer_id)