Add Franchise and Newsletter management features

- Implemented FranchiseController with CRUD operations and data handling.
- Created NewsletterController for managing newsletter subscriptions.
- Added routes for Franchise and Newsletter resources in web.php.
- Developed views for Franchise and Newsletter management including index, create, edit, and datatable actions.
- Introduced form handling and validation for Franchise and Newsletter submissions.
- Created database migrations for franchises and newsletters tables.
- Updated sidebar configuration to include Franchise and Newsletter sections.
- Enhanced client-side forms with AJAX submission for Franchise and Newsletter.
This commit is contained in:
2025-08-21 23:23:38 +05:45
parent 7f9d6bc8ec
commit d29b3ba489
23 changed files with 843 additions and 79 deletions

View File

@@ -0,0 +1,116 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Rules\Recaptcha;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Validator;
use Modules\CCMS\Models\Franchise;
use Yajra\DataTables\Facades\DataTables;
class FranchiseController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
if (request()->ajax()) {
$model = Franchise::query()->latest();
return DataTables::eloquent($model)
->addIndexColumn()
->addColumn('action', 'ccms::franchise.datatable.action')
->rawColumns(['action'])
->toJson();
}
return view('ccms::franchise.index', [
'title' => 'Franchise List',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
try {
$rules = [
'first_name' => 'required|string',
'email' => 'required|email',
];
if (setting('enable_reCaptcha') == 1) {
$rules['g-recaptcha-response'] = ['required', new Recaptcha];
}
$messages = [
'email.email' => 'Must be a valid email address.',
'g-recaptcha-response.required' => 'Please complete reCAPTCHA validation.',
'g-recaptcha-response' => 'Invalid reCAPTCHA.',
];
$validator = Validator::make($request->all(), $rules, $messages);
if ($validator->fails()) {
return response()->json(['errors' => $validator->errors()], 422);
}
Franchise::create($validator->validated());
return response()->json(['status' => 200, 'message' => "Thank you for reaching out! Your message has been received and we'll get back to you shortly."], 200);
} catch (\Exception $e) {
return response()->json(['status' => 500, 'message' => 'Internal server error', 'error' => $e->getMessage()], 500);
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$franchise = Franchise::whereId($id)->first();
if ($franchise) {
$franchise->delete();
}
return response()->json(['status' => 200, 'message' => 'Franchise has been deleted!'], 200);
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage());
}
}
}