created coupon CRUD
Cette révision appartient à :
Parent
addbb796bd
révision
3707c78e45
99
app/Http/Controllers/CouponController.php
Fichier normal
99
app/Http/Controllers/CouponController.php
Fichier normal
@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Coupon;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CouponController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$coupon= Coupon::get();
|
||||
return view('backend.coupon.index', compact('coupon'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('backend.coupon.create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
try {
|
||||
$coupon = new Coupon;
|
||||
$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');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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');
|
||||
}
|
||||
}
|
||||
11
app/Models/Coupon.php
Fichier normal
11
app/Models/Coupon.php
Fichier normal
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Coupon extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
32
database/migrations/2023_12_09_135359_create_coupons_table.php
Fichier normal
32
database/migrations/2023_12_09_135359_create_coupons_table.php
Fichier normal
@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('coupons', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
};
|
||||
112
resources/views/backend/coupon/create.blade.php
Fichier normal
112
resources/views/backend/coupon/create.blade.php
Fichier normal
@ -0,0 +1,112 @@
|
||||
@extends('backend.layouts.app')
|
||||
@section('title', 'Add Coupon')
|
||||
|
||||
@push('styles')
|
||||
<!-- Pick date -->
|
||||
<link rel="stylesheet" href="{{asset('public/vendor/pickadate/themes/default.css')}}">
|
||||
<link rel="stylesheet" href="{{asset('public/vendor/pickadate/themes/default.date.css')}}">
|
||||
@endpush
|
||||
|
||||
@section('content')
|
||||
|
||||
<!--**********************************
|
||||
Content body start
|
||||
***********************************-->
|
||||
<div class="content-body">
|
||||
<!-- row -->
|
||||
<div class="container-fluid">
|
||||
|
||||
<div class="row page-titles mx-0">
|
||||
<div class="col-sm-6 p-md-0">
|
||||
<div class="welcome-text">
|
||||
<h4>Add Coupon</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6 p-md-0 justify-content-sm-end mt-2 mt-sm-0 d-flex">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="{{route('dashboard')}}">Home</a></li>
|
||||
<li class="breadcrumb-item active"><a href="{{route('coupon.index')}}">Coupons</a></li>
|
||||
<li class="breadcrumb-item active"><a href="{{route('coupon.create')}}">Add Coupon</a>
|
||||
</li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xl-12 col-xxl-12 col-sm-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="card-title">Coupon Info</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="{{route('coupon.store')}}" method="post" enctype="multipart/form-data">
|
||||
@csrf
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Coupon Code</label>
|
||||
<input type="text" class="form-control" name="code"
|
||||
value="{{old('code')}}">
|
||||
</div>
|
||||
@if($errors->has('code'))
|
||||
<span class="text-danger"> {{$errors->first('code')}}</span>
|
||||
@endif
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Discount</label>
|
||||
<input type="text" class="form-control" name="discount"
|
||||
value="{{old('discount')}}">
|
||||
</div>
|
||||
@if($errors->has('discount'))
|
||||
<span class="text-danger"> {{$errors->first('discount')}}</span>
|
||||
@endif
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Valid From</label>
|
||||
<input type="date" class="form-control" name="valid_from"
|
||||
value="{{old('valid_from')}}">
|
||||
</div>
|
||||
@if($errors->has('valid_from'))
|
||||
<span class="text-danger"> {{$errors->first('valid_from')}}</span>
|
||||
@endif
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Valid Until</label>
|
||||
<input type="date" class="form-control" name="valid_until"
|
||||
value="{{old('valid_until')}}">
|
||||
</div>
|
||||
@if($errors->has('valid_until'))
|
||||
<span class="text-danger"> {{$errors->first('valid_until')}}</span>
|
||||
@endif
|
||||
</div>
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<button type="submit" class="btn btn-light">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!--**********************************
|
||||
Content body end
|
||||
***********************************-->
|
||||
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<!-- pickdate -->
|
||||
<script src="{{asset('public/vendor/pickadate/picker.js')}}"></script>
|
||||
<script src="{{asset('public/vendor/pickadate/picker.time.js')}}"></script>
|
||||
<script src="{{asset('public/vendor/pickadate/picker.date.js')}}"></script>
|
||||
|
||||
<!-- Pickdate -->
|
||||
<script src="{{asset('public/js/plugins-init/pickadate-init.js')}}"></script>
|
||||
@endpush
|
||||
113
resources/views/backend/coupon/edit.blade.php
Fichier normal
113
resources/views/backend/coupon/edit.blade.php
Fichier normal
@ -0,0 +1,113 @@
|
||||
@extends('backend.layouts.app')
|
||||
@section('title', 'Edit Coupon')
|
||||
|
||||
@push('styles')
|
||||
<!-- Pick date -->
|
||||
<link rel="stylesheet" href="{{asset('public/vendor/pickadate/themes/default.css')}}">
|
||||
<link rel="stylesheet" href="{{asset('public/vendor/pickadate/themes/default.date.css')}}">
|
||||
@endpush
|
||||
|
||||
@section('content')
|
||||
|
||||
<!--**********************************
|
||||
Content body start
|
||||
***********************************-->
|
||||
<div class="content-body">
|
||||
<!-- row -->
|
||||
<div class="container-fluid">
|
||||
|
||||
<div class="row page-titles mx-0">
|
||||
<div class="col-sm-6 p-md-0">
|
||||
<div class="welcome-text">
|
||||
<h4>Edit Coupon</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6 p-md-0 justify-content-sm-end mt-2 mt-sm-0 d-flex">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="{{route('dashboard')}}">Home</a></li>
|
||||
<li class="breadcrumb-item active"><a href="{{route('coupon.index')}}">Coupons</a></li>
|
||||
<li class="breadcrumb-item active"><a href="javascript:void(0);">Edit Coupon</a></li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xl-12 col-xxl-12 col-sm-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h5 class="card-title">Coupon Info</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="{{ route('coupon.update', $coupon->id) }}" method="post"
|
||||
enctype="multipart/form-data">
|
||||
@csrf
|
||||
@method('PATCH')
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Coupon Code</label>
|
||||
<input type="text" class="form-control" name="code"
|
||||
value="{{old('code', $coupon->code)}}">
|
||||
</div>
|
||||
@if($errors->has('code'))
|
||||
<span class="text-danger"> {{ $errors->first('code') }}</span>
|
||||
@endif
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Discount</label>
|
||||
<input type="text" class="form-control" name="discount"
|
||||
value="{{old('discount', $coupon->discount)}}">
|
||||
</div>
|
||||
@if($errors->has('discount'))
|
||||
<span class="text-danger"> {{ $errors->first('discount') }}</span>
|
||||
@endif
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Valid From</label>
|
||||
<input type="text" class="form-control" name="valid_from"
|
||||
value="{{old('valid_from', $coupon->valid_from)}}">
|
||||
</div>
|
||||
@if($errors->has('valid_from'))
|
||||
<span class="text-danger"> {{ $errors->first('valid_from') }}</span>
|
||||
@endif
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<div class="form-group">
|
||||
<label class="form-label">Valid Until</label>
|
||||
<input type="text" class="form-control" name="valid_until"
|
||||
value="{{old('valid_until', $coupon->valid_until)}}">
|
||||
</div>
|
||||
@if($errors->has('valid_until'))
|
||||
<span class="text-danger"> {{ $errors->first('valid_until') }}</span>
|
||||
@endif
|
||||
</div>
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<button type="submit" class="btn btn-light">Cencel</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!--**********************************
|
||||
Content body end
|
||||
***********************************-->
|
||||
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<!-- pickdate -->
|
||||
<script src="{{asset('public/vendor/pickadate/picker.js')}}"></script>
|
||||
<script src="{{asset('public/vendor/pickadate/picker.time.js')}}"></script>
|
||||
<script src="{{asset('public/vendor/pickadate/picker.date.js')}}"></script>
|
||||
|
||||
<!-- Pickdate -->
|
||||
<script src="{{asset('public/js/plugins-init/pickadate-init.js')}}"></script>
|
||||
@endpush
|
||||
105
resources/views/backend/coupon/index.blade.php
Fichier normal
105
resources/views/backend/coupon/index.blade.php
Fichier normal
@ -0,0 +1,105 @@
|
||||
@extends('backend.layouts.app')
|
||||
@section('title', 'Coupon List')
|
||||
|
||||
@push('styles')
|
||||
<!-- Datatable -->
|
||||
<link href="{{asset('public/vendor/datatables/css/jquery.dataTables.min.css')}}" rel="stylesheet">
|
||||
@endpush
|
||||
|
||||
@section('content')
|
||||
|
||||
<!--**********************************
|
||||
Content body start
|
||||
***********************************-->
|
||||
<div class="content-body">
|
||||
<!-- row -->
|
||||
<div class="container-fluid">
|
||||
|
||||
<div class="row page-titles mx-0">
|
||||
<div class="col-sm-6 p-md-0">
|
||||
<div class="welcome-text">
|
||||
<h4>Coupon List</h4>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-sm-6 p-md-0 justify-content-sm-end mt-2 mt-sm-0 d-flex">
|
||||
<ol class="breadcrumb">
|
||||
<li class="breadcrumb-item"><a href="{{route('dashboard')}}">Home</a></li>
|
||||
<li class="breadcrumb-item active"><a href="{{route('coupon.index')}}">Coupons</a></li>
|
||||
<li class="breadcrumb-item active"><a href="{{route('coupon.index')}}">All Coupon</a></li>
|
||||
</ol>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="row tab-content">
|
||||
<div id="list-view" class="tab-pane fade active show col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h4 class="card-title">All Coupons List </h4>
|
||||
<a href="{{route('coupon.create')}}" class="btn btn-primary">+ Add new</a>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table id="example3" class="display" style="min-width: 845px">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{__('#')}}</th>
|
||||
<th>{{__('Coupon Code')}}</th>
|
||||
<th>{{__('Discount')}}</th>
|
||||
<th>{{__('Valid From')}}</th>
|
||||
<th>{{__('Valid Until')}}</th>
|
||||
<th>{{__('Action')}}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@forelse ($coupon as $c)
|
||||
<tr>
|
||||
<td>{{$c->id}}</td>
|
||||
<td><strong>{{$c->code}}</strong></td>
|
||||
<td><strong>{{$c->discount}}</strong></td>
|
||||
<td>{{$c->valid_from}}</td>
|
||||
<td>{{$c->valid_until}}</td>
|
||||
<td>
|
||||
<a href="{{route('coupon.edit', $c->id)}}"
|
||||
class="btn btn-sm btn-primary" title="Edit"><i
|
||||
class="la la-pencil"></i></a>
|
||||
<a href="javascript:void(0);" class="btn btn-sm btn-danger"
|
||||
title="Delete" onclick="$('#form{{$c->id}}').submit()"><i
|
||||
class="la la-trash-o"></i></a>
|
||||
<form id="form{{$c->id}}"
|
||||
action="{{route('coupon.destroy', $c->id)}}"
|
||||
method="post">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<th colspan="7" class="text-center">No Coupon Found</th>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<!--**********************************
|
||||
Content body end
|
||||
***********************************-->
|
||||
|
||||
@endsection
|
||||
|
||||
@push('scripts')
|
||||
<!-- Datatable -->
|
||||
<script src="{{asset('public/vendor/datatables/js/jquery.dataTables.min.js')}}"></script>
|
||||
<script src="{{asset('public/js/plugins-init/datatables.init.js')}}"></script>
|
||||
@endpush
|
||||
@ -201,14 +201,16 @@ class="feather feather-log-out">
|
||||
</a>
|
||||
</li>
|
||||
<li class="nav-label">Main Menu</li>
|
||||
<li><a class="" href="{{route('role.index')}}" aria-expanded="false">
|
||||
<i class="las la-cog"></i>
|
||||
<span class="nav-text">Permissions</span>
|
||||
</a>
|
||||
</li>
|
||||
<li><a class="has-arrow" href="javascript:void()" aria-expanded="false">
|
||||
<i class="la la-cog"></i>
|
||||
<span class="nav-text">Setting</span>
|
||||
<i class="la la-universal-access"></i>
|
||||
<span class="nav-text">Roles</span>
|
||||
</a>
|
||||
<ul aria-expanded="false">
|
||||
<li><a href="{{route('role.index')}}"><i class="las la-universal-access"></i>Roles
|
||||
& Permissions</a>
|
||||
</li>
|
||||
<li><a href="{{route('user.index')}}"><i class="la la-users"></i>Users</a></li>
|
||||
<li><a href="{{route('instructor.index')}}"><i
|
||||
class="las la-chalkboard-teacher"></i>Instructors</a>
|
||||
@ -238,8 +240,8 @@ class="las la-chalkboard-teacher"></i>Instructors</a>
|
||||
<li><a href="{{route('quiz.index')}}"><i class="las la-icons"></i>All Quizzes</a></li>
|
||||
<li><a href="{{route('question.index')}}"><i
|
||||
class="las la-question-circle"></i>Questions</a></li>
|
||||
<li><a href="{{route('option.index')}}"><i class="las la-stream"></i>Options</a></li>
|
||||
<li><a href="{{route('answer.index')}}"><i class="las la-font"></i>Answers</a></li>
|
||||
{{-- <li><a href="{{route('option.index')}}"><i class="las la-stream"></i>Options</a></li>
|
||||
<li><a href="{{route('answer.index')}}"><i class="las la-font"></i>Answers</a></li> --}}
|
||||
</ul>
|
||||
</li>
|
||||
<li><a class="has-arrow" href="javascript:void()" aria-expanded="false">
|
||||
@ -269,6 +271,7 @@ class="las la-question-circle"></i>Questions</a></li>
|
||||
<ul aria-expanded="false">
|
||||
<li><a href="javascript:void()"><i class="las la-money-bill"></i>Course Fees</a></li>
|
||||
<li><a href="javascript:void()"><i class="lab la-gg-circle"></i>Subscription Fees</a></li>
|
||||
<li><a href="{{route('coupon.index')}}"><i class="las la-tags"></i>Coupons</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
@ -144,7 +144,8 @@ class="feather feather-search">
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{{-- Mobile Navbar --}}
|
||||
<div class="navbar-mobile">
|
||||
<div>
|
||||
<div class="navbar-mobile__top">
|
||||
@ -591,7 +592,7 @@ function toggleDropdown(event) {
|
||||
@endif
|
||||
</script>
|
||||
|
||||
@stack('scripts')
|
||||
@stack('scripts')
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
@ -21,6 +21,7 @@
|
||||
use App\Http\Controllers\CartController;
|
||||
use App\Http\Controllers\HomeController;
|
||||
use App\Http\Controllers\CheckoutController;
|
||||
use App\Http\Controllers\CouponController as coupon;
|
||||
|
||||
/* students */
|
||||
use App\Http\Controllers\Students\AuthController as sauth;
|
||||
@ -64,6 +65,7 @@
|
||||
Route::resource('review', review::class);
|
||||
Route::resource('discussion', discussion::class);
|
||||
Route::resource('message', message::class);
|
||||
Route::resource('coupon', coupon::class);
|
||||
Route::get('permission/{role}', [permission::class, 'index'])->name('permission.list');
|
||||
Route::post('permission/{role}', [permission::class, 'save'])->name('permission.save');
|
||||
});
|
||||
|
||||
Chargement…
Référencer dans un nouveau ticket
Block a user