1<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
2 Open Form
3</button>
4
5<!-- Modal -->
6<div wire:ignore.self class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
7 <div class="modal-dialog" role="document">
8 <div class="modal-content">
9 <div class="modal-header">
10 <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
11 <button type="button" class="close" data-dismiss="modal" aria-label="Close">
12 <span aria-hidden="true close-btn">×</span>
13 </button>
14 </div>
15 <div class="modal-body">
16 <form>
17 <div class="form-group">
18 <label for="exampleFormControlInput1">Name</label>
19 <input type="text" class="form-control" id="exampleFormControlInput1" placeholder="Enter Name" wire:model="name">
20 @error('name') <span class="text-danger error">{{ $message }}</span>@enderror
21 </div>
22 <div class="form-group">
23 <label for="exampleFormControlInput2">Email address</label>
24 <input type="email" class="form-control" id="exampleFormControlInput2" wire:model="email" placeholder="Enter Email">
25 @error('email') <span class="text-danger error">{{ $message }}</span>@enderror
26 </div>
27 </form>
28 </div>
29 <div class="modal-footer">
30 <button type="button" class="btn btn-secondary close-btn" data-dismiss="modal">Close</button>
31 <button type="button" wire:click.prevent="store()" class="btn btn-primary close-modal">Save changes</button>
32 </div>
33 </div>
34 </div>
35</div>
1<?php
2namespace App\Http\Controllers;
3use Illuminate\Http\Request;
4use App\Customer;
5use Redirect,Response;
6class CustomerController extends Controller
7{
8
9 /**
10 * Display a listing of the resource.
11 *
12 * @return \Illuminate\Http\Response
13 */
14
15 public function index()
16 {
17 $customers = Customer::latest()->paginate(4);
18 return view('customers.index',compact('customers'))->with('i', (request()->input('page', 1) - 1) * 4);
19 }
20
21 /**
22 * Show the form for creating a new resource.
23 *
24 * @return \Illuminate\Http\Response
25 */
26
27 public function create()
28 {
29 return view('customers.create');
30 }
31
32 /**
33 * Store a newly created resource in storage.
34 *
35 * @param \Illuminate\Http\Request $request
36 * @return \Illuminate\Http\Response
37 */
38
39 public function store(Request $request)
40 {
41
42 $r=$request->validate([
43 'name' => 'required',
44 'email' => 'required',
45 'address' => 'required',
46 ]);
47
48 $custId = $request->cust_id;
49 Customer::updateOrCreate(['id' => $custId],['name' => $request->name, 'email' => $request->email,'address'=>$request->address]);
50 if(empty($request->cust_id))
51 $msg = 'Customer entry created successfully.';
52 else
53 $msg = 'Customer data is updated successfully';
54 return redirect()->route('customers.index')->with('success',$msg);
55 }
56
57 /**
58 * Display the specified resource.
59 *
60 * @param int $id
61 * @return \Illuminate\Http\Response
62 */
63
64 public function show(Customer $customer)
65 {
66 return view('customers.show',compact('customer'));
67 }
68
69 /**
70 * Show the form for editing the specified resource.
71 *
72 * @param int $id
73 * @return \Illuminate\Http\Response
74 */
75
76 public function edit($id)
77 {
78 $where = array('id' => $id);
79 $customer = Customer::where($where)->first();
80 return Response::json($customer);
81 }
82
83 /**
84 * Update the specified resource in storage.
85 *
86 * @param \Illuminate\Http\Request $request
87 * @param int $id
88 * @return \Illuminate\Http\Response
89 */
90
91 public function update(Request $request)
92 {
93
94 }
95
96 /**
97 * Remove the specified resource from storage.
98 *
99 * @param int $id
100 * @return \Illuminate\Http\Response
101 */
102
103 public function destroy($id)
104 {
105 $cust = Customer::where('id',$id)->delete();
106 return Response::json($cust);
107 }
108}
109