From 3707c78e4559bd321e0aaf085ad60e61b3c4f1e2 Mon Sep 17 00:00:00 2001 From: Ibrahim Khalil Shakil Date: Sat, 9 Dec 2023 21:39:17 +0600 Subject: [PATCH] created coupon CRUD --- app/Http/Controllers/CouponController.php | 99 +++++++++++++++ app/Models/Coupon.php | 11 ++ ...2023_12_09_135359_create_coupons_table.php | 32 +++++ .../views/backend/coupon/create.blade.php | 112 +++++++++++++++++ resources/views/backend/coupon/edit.blade.php | 113 ++++++++++++++++++ .../views/backend/coupon/index.blade.php | 105 ++++++++++++++++ resources/views/backend/layouts/app.blade.php | 17 +-- .../views/frontend/layouts/app.blade.php | 5 +- routes/web.php | 2 + 9 files changed, 487 insertions(+), 9 deletions(-) create mode 100644 app/Http/Controllers/CouponController.php create mode 100644 app/Models/Coupon.php create mode 100644 database/migrations/2023_12_09_135359_create_coupons_table.php create mode 100644 resources/views/backend/coupon/create.blade.php create mode 100644 resources/views/backend/coupon/edit.blade.php create mode 100644 resources/views/backend/coupon/index.blade.php diff --git a/app/Http/Controllers/CouponController.php b/app/Http/Controllers/CouponController.php new file mode 100644 index 0000000..69a9329 --- /dev/null +++ b/app/Http/Controllers/CouponController.php @@ -0,0 +1,99 @@ +code = $request->code; + $coupon->discount = $request->discount; + $coupon->valid_from = $request->valid_from; + $coupon->valid_until = $request->valid_until; + + if($coupon->save()) + return redirect()->route('coupon.index')->with('success','Data Saved'); + else + return redirect()->back()->withInput()->with('error', 'Please try again'); + } catch (\Exception $e) { + dd($e); + return redirect()->back()->withInput()->with('error', 'Please try again'); + } + } + + /** + * Display the specified resource. + */ + public function show(Coupon $coupon) + { + // + } + + /** + * Show the form for editing the specified resource. + */ + public function edit($id) + { + $coupon = Coupon::findOrFail($id); + return view('backend.coupon.edit', compact('coupon')); + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, $id) + { + try { + $coupon = Coupon::findOrFail($id); + $coupon->code = $request->code; + $coupon->discount = $request->discount; + $coupon->valid_from = $request->valid_from; + $coupon->valid_until = $request->valid_until; + + if ($coupon->save()) + return redirect()->route('coupon.index')->with('success', 'Data Saved'); + else + return redirect()->back()->withInput()->with('error', 'Please try again'); + } catch (\Exception $e) { + dd($e); + return redirect()->back()->withInput()->with('error', 'Please try again'); + } + } + + /** + * Remove the specified resource from storage. + */ + public function destroy($id) + { + $coupon = Coupon::findOrFail($id); + + if($coupon->delete()) + return redirect()->back()->with('error','Data Deleted'); + } +} diff --git a/app/Models/Coupon.php b/app/Models/Coupon.php new file mode 100644 index 0000000..d5459dc --- /dev/null +++ b/app/Models/Coupon.php @@ -0,0 +1,11 @@ +id(); + $table->string('code')->unique(); + $table->decimal('discount', 8, 2); + $table->timestamp('valid_from')->nullable(); + $table->timestamp('valid_until')->nullable(); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('coupons'); + } +}; diff --git a/resources/views/backend/coupon/create.blade.php b/resources/views/backend/coupon/create.blade.php new file mode 100644 index 0000000..c29f656 --- /dev/null +++ b/resources/views/backend/coupon/create.blade.php @@ -0,0 +1,112 @@ +@extends('backend.layouts.app') +@section('title', 'Add Coupon') + +@push('styles') + + + +@endpush + +@section('content') + + +
+ +
+ +
+
+
+

Add Coupon

+
+
+
+ +
+
+ +
+
+
+
+
Coupon Info
+
+
+
+ @csrf +
+
+
+ + +
+ @if($errors->has('code')) + {{$errors->first('code')}} + @endif +
+
+
+ + +
+ @if($errors->has('discount')) + {{$errors->first('discount')}} + @endif +
+
+
+ + +
+ @if($errors->has('valid_from')) + {{$errors->first('valid_from')}} + @endif +
+
+
+ + +
+ @if($errors->has('valid_until')) + {{$errors->first('valid_until')}} + @endif +
+
+ + +
+
+
+
+
+
+
+ +
+
+ + +@endsection + +@push('scripts') + + + + + + + +@endpush \ No newline at end of file diff --git a/resources/views/backend/coupon/edit.blade.php b/resources/views/backend/coupon/edit.blade.php new file mode 100644 index 0000000..d25f941 --- /dev/null +++ b/resources/views/backend/coupon/edit.blade.php @@ -0,0 +1,113 @@ +@extends('backend.layouts.app') +@section('title', 'Edit Coupon') + +@push('styles') + + + +@endpush + +@section('content') + + +
+ +
+ +
+
+
+

Edit Coupon

+
+
+
+ +
+
+ +
+
+
+
+
Coupon Info
+
+
+
+ @csrf + @method('PATCH') +
+
+
+ + +
+ @if($errors->has('code')) + {{ $errors->first('code') }} + @endif +
+
+
+ + +
+ @if($errors->has('discount')) + {{ $errors->first('discount') }} + @endif +
+
+
+ + +
+ @if($errors->has('valid_from')) + {{ $errors->first('valid_from') }} + @endif +
+
+
+ + +
+ @if($errors->has('valid_until')) + {{ $errors->first('valid_until') }} + @endif +
+
+ + +
+
+
+
+
+
+
+ +
+
+ + +@endsection + +@push('scripts') + + + + + + + +@endpush \ No newline at end of file diff --git a/resources/views/backend/coupon/index.blade.php b/resources/views/backend/coupon/index.blade.php new file mode 100644 index 0000000..4a13cd3 --- /dev/null +++ b/resources/views/backend/coupon/index.blade.php @@ -0,0 +1,105 @@ +@extends('backend.layouts.app') +@section('title', 'Coupon List') + +@push('styles') + + +@endpush + +@section('content') + + +
+ +
+ +
+
+
+

Coupon List

+
+
+
+ +
+
+ +
+
+
+
+
+
+

All Coupons List

+ + Add new +
+
+
+ + + + + + + + + + + + + @forelse ($coupon as $c) + + + + + + + + + @empty + + + + @endforelse + +
{{__('#')}}{{__('Coupon Code')}}{{__('Discount')}}{{__('Valid From')}}{{__('Valid Until')}}{{__('Action')}}
{{$c->id}}{{$c->code}}{{$c->discount}}{{$c->valid_from}}{{$c->valid_until}} + + +
+ @csrf + @method('DELETE') +
+
No Coupon Found
+
+
+
+
+
+
+
+ +
+
+ + +@endsection + +@push('scripts') + + + +@endpush \ No newline at end of file diff --git a/resources/views/backend/layouts/app.blade.php b/resources/views/backend/layouts/app.blade.php index 4151e63..76834af 100644 --- a/resources/views/backend/layouts/app.blade.php +++ b/resources/views/backend/layouts/app.blade.php @@ -201,14 +201,16 @@ class="feather feather-log-out"> +
  • +
  • diff --git a/resources/views/frontend/layouts/app.blade.php b/resources/views/frontend/layouts/app.blade.php index ff51797..b24a95c 100644 --- a/resources/views/frontend/layouts/app.blade.php +++ b/resources/views/frontend/layouts/app.blade.php @@ -144,7 +144,8 @@ class="feather feather-search"> @endif - + + {{-- Mobile Navbar --}}