/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create($id) { $data = DataIn::findOrFail($id); $enquiry_user = EnquiryUser::where('phone', '=', $data->who)->get(); $enquiry = new OpenEnquiry(); if ($enquiry_user->count() == 0) { $enquiry_user = new EnquiryUser(); $enquiry_user->phone = $data->who; $enquiry_user->save(); $enquiry->enquiry_user_id = $enquiry_user->id; } else { $enquiry->enquiry_user_id = $enquiry_user[0]->id; } $enquiry->in_time = $data->DateTime; $enquiry->save(); $data->delete(); return redirect('enquiry/view-ticket/' . $enquiry->id); }