Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function store(Request $request)
- {
- $temparr = [];
- $customer = new Customer();
- $department = new DepartMent();
- dd($request->all());
- /* Testing for empty/null values */
- foreach ($request->all() as $key => $value) {
- if (is_array($value)) {
- $temparr = array_filter($value);
- $request[$key] = $temparr;
- }
- }
- /* Validations */
- $validatedData = $request->validate([
- 'owner_name' => 'required',
- 'pincode' => 'numeric|nullable',
- 'number' => 'numeric|nullable',
- ]);
- $customer->owner_name = $request['owner_name'];
- $customer->country = $request['country'];
- $customer->state = $request['state'];
- $customer->city = $request['city'];
- $customer->pincode = $request['pincode'];
- $customer->number = $request['number'];
- $customer->correspondance_check = $request['correspondance_check'];
- $res = $customer->save();
- $result = Customer::select('id')->where('owner_name', $request->owner_name)->first();
- $department->customer_id = $result->id;
- $department->department_name = $request->department_name;
- $department->person_name = $request->person_name;
- $department->person_number = $request->person_number;
- $department->person_email = $request->person_email;
- $department->notification_flag = $request->notification_check;
- $department->notification_type = $request->notification_type;
- foreach ($department->department_name as $key => $n) {
- // DB::table('users_dependents')->insert(
- $customer->department()->saveMany(
- array(
- 'customer_id' => $department->customer_id[$key],
- 'department_name' => $department->department_name[$key],
- 'person_name' => $department->person_name[$key],
- 'person_number' => $department->person_number[$key],
- 'person_email' => $department->person_email[$key],
- 'notification_flag' => $department->notification_flag[$key],
- 'notification_type' => $department->notification_type[$key],
- )
- );
- }
- return redirect('admin/customers');
- // return response()->json($customerData);
- }
- class Customer extends Model
- {
- protected $fillable = ['owner_name', 'address', 'country', 'state', 'city', 'pincode', 'number', 'correspondance_check'];
- public function department()
- {
- return $this->hasMany('AppDepartment');
- }
- }
- class Department extends Model
- {
- protected $fillable = ['customer_id', 'department_name', 'person_name', 'person_number', 'person_email', 'notification_flag', 'notification_type'];
- public function customer()
- {
- return $this->belongsTo('AppCustomer');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement