first change

This commit is contained in:
2025-07-27 17:40:56 +05:45
commit f8b9a6725b
3152 changed files with 229528 additions and 0 deletions

View File

@@ -0,0 +1,152 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Modules\CCMS\Models\Blog;
use Modules\CCMS\Models\Category;
use Yajra\DataTables\Facades\DataTables;
class BlogController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
if (request()->ajax()) {
$model = Blog::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('image', function (Blog $blog) {
return $blog->getRawOriginal('image') ? "<img src='{$blog->image}' alt='{$blog->title}' class='rounded avatar-sm material-shadow ms-2 img-thumbnail'>" : '-';
})
->editColumn('date', '{!! getFormatted(date:$date) ?? "N/A" !!}')
->editColumn('status', function (Blog $blog) {
$status = $blog->status ? 'Published' : 'Draft';
$color = $blog->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::blog.datatable.action')
->rawColumns(['image', 'status', 'action'])
->toJson();
}
return view('ccms::blog.index', [
'title' => 'Blog List',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$categoryOptions = Category::pluck('title', 'id');
return view('ccms::blog.create', [
'title' => 'Create Blog',
'editable' => false,
'categoryOptions' => $categoryOptions,
]);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$maxOrder = Blog::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'slug' => Str::slug($request->title),
'order' => $order,
]);
try {
$validated = $request->validate([
'title' => 'required',
]);
Blog::create($request->all());
flash()->success("Blog has been created!");
return redirect()->route('blog.index');
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage())->withInput();
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('ccms::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$categoryOptions = Category::pluck('title', 'id');
$blog = Blog::findOrFail($id);
return view('ccms::blog.edit', [
'title' => 'Edit Blog',
'editable' => true,
'blog' => $blog,
'categoryOptions' => $categoryOptions,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
$request->merge([
'slug' => Str::slug($request->title),
]);
$validated = $request->validate([]);
$blog = Blog::findOrFail($id);
$blog->update($request->all());
flash()->success("Blog has been updated.");
return redirect()->back();
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
$blog = Blog::findOrFail($id);
$blog->delete();
return response()->json(['status' => 200, 'message' => "Blog has been deleted."], 200);
}
public function reorder(Request $request)
{
$blogs = Blog::all();
foreach ($blogs as $blog) {
foreach ($request->order as $order) {
if ($order['id'] == $blog->id) {
$blog->update(['order' => $order['position']]);
}
}
}
return response(['status' => true, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$blog = Blog::findOrFail($id);
$blog->update(['status' => !$blog->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}

View File

@@ -0,0 +1,145 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Modules\CCMS\Models\Branch;
use Yajra\DataTables\Facades\DataTables;
class BranchController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
if (request()->ajax()) {
$model = Branch::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('image', function (Branch $branch) {
return $branch->getRawOriginal('image') ? "<img src='{$branch->image}' alt='{$branch->title}' class='rounded avatar-sm material-shadow ms-2 img-thumbnail'>" : '-';
})
->editColumn('status', function (Branch $branch) {
$status = $branch->status ? 'Published' : 'Draft';
$color = $branch->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::branch.datatable.action')
->rawColumns(['image', 'status', 'action'])
->toJson();
}
return view('ccms::branch.index', [
'title' => 'Branch List',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('ccms::branch.create', [
'title' => 'Create Branch',
'editable' => false,
]);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$maxOrder = Branch::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'slug' => Str::slug($request->title),
'order' => $order,
]);
try {
$validated = $request->validate([
'title' => 'required',
]);
Branch::create($request->all());
flash()->success("Branch has been created!");
return redirect()->route('branch.index');
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage())->withInput();
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('ccms::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$branch = Branch::findOrFail($id);
return view('ccms::branch.edit', [
'title' => 'Edit Branch',
'editable' => true,
'branch' => $branch,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
$request->merge([
'slug' => Str::slug($request->title),
]);
$validated = $request->validate([]);
$branch = Branch::findOrFail($id);
$branch->update($request->all());
flash()->success("Branch has been updated.");
return redirect()->back();
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
$branch = Branch::findOrFail($id);
$branch->delete();
return response()->json(['status' => 200, 'message' => "Branch has been deleted."], 200);
}
public function reorder(Request $request)
{
$branchs = Branch::all();
foreach ($branchs as $branch) {
foreach ($request->order as $order) {
if ($order['id'] == $branch->id) {
$branch->update(['order' => $order['position']]);
}
}
}
return response(['status' => true, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$branch = Branch::findOrFail($id);
$branch->update(['status' => !$branch->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}

View File

@@ -0,0 +1,155 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Modules\CCMS\Models\Category;
use Modules\CCMS\Services\CategoryService;
use Yajra\DataTables\Facades\DataTables;
class CategoryController extends Controller
{
protected $categoryService;
public function __construct(CategoryService $categoryService)
{
$this->categoryService = $categoryService;
}
/**
* Display a listing of the resource.
*/
public function index(?int $id = null)
{
$isEditing = !is_null($id);
$category = $isEditing ? $this->categoryService->getCategoryById($id) : null;
if (request()->ajax()) {
$model = Category::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('status', function (Category $category) {
$status = $category->status ? 'Published' : 'Draft';
$color = $category->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::category.datatable.action')
->rawColumns(['action', 'status'])
->toJson();
}
return view('ccms::category.index', [
'category' => $category,
'title' => $isEditing ? 'Edit Category' : 'Add Category',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$isEditing = $request->has('id');
$request->merge([
'slug' => Str::slug($request->title),
]);
if ($isEditing) {
$validated = $request->validate([
'title' => ['required', 'string', 'max:255','unique:categories,title,'.$request->id],
'slug' => ['required', 'string'],
]);
$category = $this->categoryService->updateCategory($request->id, categoryData: $validated);
flash()->success("Category for {$category->title} has been updated.");
return to_route('category.index');
}
$maxOrder = Category::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'order' => $order
]);
$validated = $request->validate([
'title' => ['required', 'string','unique:categories,title'],
'slug' => ['required', 'string'],
'order' => ['integer'],
]);
$category = $this->categoryService->storeCategory($validated);
flash()->success("Category for {$category->title} has been created.");
return to_route('category.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$category = $this->categoryService->getCategoryById($id);
return view('ccms::category.edit', [
'category' => $category,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
$category = $this->categoryService->deleteCategory($id);
return response()->json(['status' => 200, 'message' => "Category has been deleted."], 200);
}
public function reorder(Request $request)
{
$categorys = $this->categoryService->getAllCategories();
foreach ($categorys as $category) {
foreach ($request->order as $order) {
if ($order['id'] == $category->id) {
$category->update(['order' => $order['position']]);
}
}
}
return response(['status' => true, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$category = Category::findOrFail($id);
$category->update(['status' => !$category->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}

View File

@@ -0,0 +1,166 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Modules\CCMS\Models\Counter;
use Modules\CCMS\Services\CounterService;
use Yajra\DataTables\Facades\DataTables;
class CounterController extends Controller
{
protected $counterService;
public function __construct(CounterService $counterService)
{
$this->counterService = $counterService;
}
/**
* Display a listing of the resource.
*/
public function index(?int $id = null)
{
$isEditing = !is_null($id);
$counter = $isEditing ? $this->counterService->getCounterById($id) : null;
if (request()->ajax()) {
$model = Counter::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('image', function (Counter $counter) {
$html = $counter->getRawOriginal('image') ? "<img src='{$counter->image}' alt='{$counter->title}' class='rounded avatar-sm material-shadow ms-2 img-thumbnail'>" : '-';
return $html;
})
->editColumn('icon', function (Counter $counter) {
return $counter->icon ?? '-';
})
->editColumn('status', function (Counter $counter) {
$status = $counter->status ? 'Published' : 'Draft';
$color = $counter->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::counter.datatable.action')
->rawColumns(['image', 'action', 'status'])
->toJson();
}
return view('ccms::counter.index', [
'counter' => $counter,
'editable' => $isEditing ? true : false,
'title' => $isEditing ? 'Edit Counter' : 'Add Counter',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$isEditing = $request->has('id');
$request->merge([
'slug' => Str::slug($request->title),
]);
if ($isEditing) {
$validated = $request->validate([
'title' => ['required', 'string', 'max:255', 'unique:counters,title,' . $request->id],
'slug' => ['required', 'string'],
'counter' => ['nullable'],
'icon' => ['nullable'],
'image' => ['nullable', 'string'],
]);
$counter = $this->counterService->updateCounter($request->id, counterData: $validated);
flash()->success("Counter for {$counter->title} has been updated.");
return to_route('counter.index');
}
$maxOrder = Counter::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'order' => $order,
]);
$validated = $request->validate([
'title' => ['required', 'string', 'unique:counters,title'],
'slug' => ['required', 'string'],
'icon' => ['nullable'],
'counter' => ['nullable'],
'image' => ['nullable', 'string'],
'order' => ['integer'],
]);
$counter = $this->counterService->storeCounter($validated);
flash()->success("Counter for {$counter->title} has been created.");
return to_route('counter.index');
}
/**
* 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)
{
$counter = $this->counterService->deleteCounter($id);
return response()->json(['status' => 200, 'message' => "Counter has been deleted."], 200);
}
public function reorder(Request $request)
{
$counters = $this->counterService->getAllCategories();
foreach ($counters as $counter) {
foreach ($request->order as $order) {
if ($order['id'] == $counter->id) {
$counter->update(['order' => $order['position']]);
}
}
}
return response(['status' => true, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$counter = Counter::findOrFail($id);
$counter->update(['status' => !$counter->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}

View File

@@ -0,0 +1,151 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Modules\CCMS\Models\Country;
use Yajra\DataTables\Facades\DataTables;
class CountryController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
if (request()->ajax()) {
$model = Country::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('image', function (Country $country) {
return "<img src='{$country->image}' alt='{$country->title}' class='rounded avatar-sm material-shadow ms-2 img-thumbnail'>";
})
->editColumn('parent_id', function (Country $country) {
return $country->parent ? "<span class='badge bg-primary p-1'>{$country->parent?->title}</span>" : '-';
})
->editColumn('status', function (Country $country) {
$status = $country->status ? 'Published' : 'Draft';
$color = $country->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::country.datatable.action')
->rawColumns(['parent_id', 'image', 'status', 'action'])
->toJson();
}
return view('ccms::country.index', [
'title' => 'Country List',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$countryOptions = Country::where('status', 1)->pluck('title', 'id');
return view('ccms::country.create', [
'title' => 'Create Country',
'editable' => false,
'countryOptions' => $countryOptions,
]);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$maxOrder = Country::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'slug' => Str::slug($request->title),
'order' => $order,
]);
try {
$validated = $request->validate([
'title' => 'required',
]);
Country::create($request->all());
flash()->success("Country has been created!");
return redirect()->route('country.index');
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage())->withInput();
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('ccms::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$countryOptions = Country::where('status', 1)->pluck('title', 'id');
$country = Country::findOrFail($id);
return view('ccms::country.edit', [
'title' => 'Edit Country',
'editable' => true,
'country' => $country,
'countryOptions' => $countryOptions,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
$request->merge([
'slug' => Str::slug($request->title),
]);
$validated = $request->validate([]);
$country = Country::findOrFail($id);
$country->update($request->all());
flash()->success("Country has been updated.");
return redirect()->back();
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
$country = Country::findOrFail($id);
$country->delete();
return response()->json(['status' => 200, 'message' => "Country has been deleted."], 200);
}
public function reorder(Request $request)
{
$countrys = Country::all();
foreach ($countrys as $country) {
foreach ($request->order as $order) {
if ($order['id'] == $country->id) {
$country->update(['order' => $order['position']]);
}
}
}
return response(['status' => true, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$country = Country::findOrFail($id);
$country->update(['status' => !$country->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}

View File

@@ -0,0 +1,143 @@
<?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\Enquiry;
use Yajra\DataTables\Facades\DataTables;
class EnquiryController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
if (request()->ajax()) {
$model = Enquiry::query()->latest();
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass(function (Enquiry $enquiry) {
return $enquiry->is_read ? 'text-muted' : 'text-dark';
})
->editColumn('class', function (Enquiry $enquiry) {
return $enquiry->class ?? '-';
})
->editColumn('subject', function (Enquiry $enquiry) {
return $enquiry->subject ?? '-';
})
->editColumn('message', function (Enquiry $enquiry) {
return $enquiry->message ?? '-';
})
->addColumn('action', 'ccms::enquiry.datatable.action')
->rawColumns(['action'])
->toJson();
}
return view('ccms::enquiry.index', [
'title' => 'Enquiry 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 = [
'name' => 'required|string',
'email' => 'required|email',
'digits:10',
'subject' => 'nullable',
'message' => 'nullable|max:250',
];
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);
}
Enquiry::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 {
$enquiry = Enquiry::whereId($id)->first();
if ($enquiry) {
$enquiry->delete();
}
return response()->json(['status' => 200, 'message' => 'Enquiry has been deleted!'], 200);
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage());
}
}
public function markAsRead($id)
{
try {
$enquiry = Enquiry::whereId($id)->first();
if ($enquiry) {
$enquiry->update(['is_read' => 1]);
}
return response()->json(['status' => 200, 'message' => 'Enquiry has been marked as read!'], 200);
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage());
}
}
}

View File

@@ -0,0 +1,155 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Modules\CCMS\Models\FaqCategory;
use Modules\CCMS\Services\FaqCategoryService;
use Yajra\DataTables\Facades\DataTables;
class FaqCategoryController extends Controller
{
protected $faqCategoryService;
public function __construct(FaqCategoryService $faqCategoryService)
{
$this->faqCategoryService = $faqCategoryService;
}
/**
* Display a listing of the resource.
*/
public function index(?int $id = null)
{
$isEditing = !is_null($id);
$faqCategory = $isEditing ? $this->faqCategoryService->getFaqCategoryById($id) : null;
if (request()->ajax()) {
$model = FaqCategory::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('status', function (FaqCategory $faqCategory) {
$status = $faqCategory->status ? 'Published' : 'Draft';
$color = $faqCategory->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::faqCategory.datatable.action')
->rawColumns(['action', 'status'])
->toJson();
}
return view('ccms::faqCategory.index', [
'faqCategory' => $faqCategory,
'title' => $isEditing ? 'Edit Faq Category' : 'Add Faq Category',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$isEditing = $request->has('id');
$request->merge([
'slug' => Str::slug($request->title),
]);
if ($isEditing) {
$validated = $request->validate([
'title' => ['required', 'string', 'max:255','unique:faq_categories,title,'.$request->id],
'slug' => ['required', 'string'],
]);
$faqCategory = $this->faqCategoryService->updateFaqCategory($request->id, faqCategoryData: $validated);
flash()->success("FaqCategory for {$faqCategory->title} has been updated.");
return to_route('faqCategory.index');
}
$maxOrder = FaqCategory::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'order' => $order
]);
$validated = $request->validate([
'title' => ['required', 'string','unique:faq_categories,title'],
'slug' => ['required', 'string'],
'order' => ['integer'],
]);
$faqCategory = $this->faqCategoryService->storeFaqCategory($validated);
flash()->success("FaqCategory for {$faqCategory->title} has been created.");
return to_route('faqCategory.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$faqCategory = $this->faqCategoryService->getFaqCategoryById($id);
return view('ccms::faqCategory.edit', [
'faqCategory' => $faqCategory,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
$faqCategory = $this->faqCategoryService->deleteFaqCategory($id);
return response()->json(['status' => 200, 'message' => "Faq Category has been deleted."], 200);
}
public function reorder(Request $request)
{
$faqCategories = $this->faqCategoryService->getAllfaqCategories();
foreach ($faqCategories as $faqCategory) {
foreach ($request->order as $order) {
if ($order['id'] == $faqCategory->id) {
$faqCategory->update(['order' => $order['position']]);
}
}
}
return response(['status' => true, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$faqCategory = FaqCategory::findOrFail($id);
$faqCategory->update(['status' => !$faqCategory->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}

View File

@@ -0,0 +1,162 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Modules\CCMS\Models\Faq;
use Modules\CCMS\Models\FaqCategory;
use Modules\CCMS\Services\FaqService;
use Yajra\DataTables\Facades\DataTables;
class FaqController extends Controller
{
protected $faqService;
public function __construct(FaqService $faqService)
{
$this->faqService = $faqService;
}
/**
* Display a listing of the resource.
*/
public function index(?int $id = null)
{
$isEditing = !is_null($id);
$faq = $isEditing ? $this->faqService->getFaqById($id) : null;
$categoryOptions = FaqCategory::pluck('title', 'id');
if (request()->ajax()) {
$model = Faq::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('category_id', function (Faq $faq) {
return $faq->category?->title ?? '-';
})
->editColumn('status', function (Faq $faq) {
$status = $faq->status ? 'Published' : 'Draft';
$color = $faq->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::faq.datatable.action')
->rawColumns(['action', 'status'])
->toJson();
}
return view('ccms::faq.index', [
'faq' => $faq,
'editable' => $isEditing ? true : false,
'title' => $isEditing ? 'Edit Faq' : 'Add Faq',
'categoryOptions' => $categoryOptions,
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$isEditing = $request->has('id');
$request->merge([
'slug' => Str::slug($request->title),
]);
if ($isEditing) {
$validated = $request->validate([
'title' => ['required', 'string', 'max:255', 'unique:faqs,title,' . $request->id],
'slug' => ['required', 'string'],
'description' => ['required', 'string'],
]);
$faq = $this->faqService->updateFaq($request->id, faqData: $validated);
flash()->success("Faq for {$faq->title} has been updated.");
return to_route('faq.index');
}
$maxOrder = Faq::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'order' => $order,
]);
$validated = $request->validate([
'title' => ['required', 'string', 'unique:faqs,title'],
'slug' => ['required', 'string'],
'description' => ['required', 'string'],
'order' => ['integer'],
]);
$faq = $this->faqService->storeFaq($validated);
flash()->success("Faq for {$faq->title} has been created.");
return to_route('faq.index');
}
/**
* 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)
{
$faq = $this->faqService->deleteFaq($id);
return response()->json(['status' => 200, 'message' => "Faq has been deleted."], 200);
}
public function reorder(Request $request)
{
$faqs = $this->faqService->getAllCategories();
foreach ($faqs as $faq) {
foreach ($request->order as $order) {
if ($order['id'] == $faq->id) {
$faq->update(['order' => $order['position']]);
}
}
}
return response(['status' => true, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$faq = Faq::findOrFail($id);
$faq->update(['status' => !$faq->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}

View File

@@ -0,0 +1,155 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Modules\CCMS\Models\GalleryCategory;
use Modules\CCMS\Services\GalleryCategoryService;
use Yajra\DataTables\Facades\DataTables;
class GalleryCategoryController extends Controller
{
protected $galleryCategoryService;
public function __construct(GalleryCategoryService $galleryCategoryService)
{
$this->galleryCategoryService = $galleryCategoryService;
}
/**
* Display a listing of the resource.
*/
public function index(?int $id = null)
{
$isEditing = !is_null($id);
$galleryCategory = $isEditing ? $this->galleryCategoryService->getGalleryCategoryById($id) : null;
if (request()->ajax()) {
$model = GalleryCategory::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('status', function (GalleryCategory $galleryCategory) {
$status = $galleryCategory->status ? 'Published' : 'Draft';
$color = $galleryCategory->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::galleryCategory.datatable.action')
->rawColumns(['action', 'status'])
->toJson();
}
return view('ccms::galleryCategory.index', [
'galleryCategory' => $galleryCategory,
'title' => $isEditing ? 'Edit Gallery Category' : 'Add Gallery Category',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$isEditing = $request->has('id');
$request->merge([
'slug' => Str::slug($request->title),
]);
if ($isEditing) {
$validated = $request->validate([
'title' => ['required', 'string', 'max:255','unique:gallery_categories,title,'.$request->id],
'slug' => ['required', 'string'],
]);
$galleryCategory = $this->galleryCategoryService->updateGalleryCategory($request->id, galleryCategoryData: $validated);
flash()->success("GalleryCategory for {$galleryCategory->title} has been updated.");
return to_route('galleryCategory.index');
}
$maxOrder = GalleryCategory::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'order' => $order
]);
$validated = $request->validate([
'title' => ['required', 'string','unique:gallery_categories,title'],
'slug' => ['required', 'string'],
'order' => ['integer'],
]);
$galleryCategory = $this->galleryCategoryService->storeGalleryCategory($validated);
flash()->success("GalleryCategory for {$galleryCategory->title} has been created.");
return to_route('galleryCategory.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$galleryCategory = $this->galleryCategoryService->getGalleryCategoryById($id);
return view('ccms::galleryCategory.edit', [
'galleryCategory' => $galleryCategory,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
$galleryCategory = $this->galleryCategoryService->deleteGalleryCategory($id);
return response()->json(['status' => 200, 'message' => "Gallery Category has been deleted."], 200);
}
public function reorder(Request $request)
{
$galleryCategories = $this->galleryCategoryService->getAllgalleryCategories();
foreach ($galleryCategories as $galleryCategory) {
foreach ($request->order as $order) {
if ($order['id'] == $galleryCategory->id) {
$galleryCategory->update(['order' => $order['position']]);
}
}
}
return response(['status' => true, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$galleryCategory = GalleryCategory::findOrFail($id);
$galleryCategory->update(['status' => !$galleryCategory->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}

View File

@@ -0,0 +1,180 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Modules\CCMS\Models\Gallery;
use Modules\CCMS\Models\GalleryCategory;
use Modules\CCMS\Services\GalleryService;
use Yajra\DataTables\Facades\DataTables;
class GalleryController extends Controller
{
protected $galleryService;
public function __construct(GalleryService $galleryService)
{
$this->galleryService = $galleryService;
}
/**
* Display a listing of the resource.
*/
public function index(?int $id = null)
{
$isEditing = !is_null($id);
$gallery = $isEditing ? $this->galleryService->getGalleryById($id) : null;
$categoryOptions = GalleryCategory::pluck('title', 'id');
if (request()->ajax()) {
$model = Gallery::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('images', function (Gallery $gallery) {
if (!empty($gallery->images)) {
$html = '<div clas="h-stack">';
foreach ($gallery->images as $image) {
$html .= "<img src='{$image}' alt='{$gallery->title}' class='rounded avatar-sm material-shadow ms-2 img-thumbnail'>";
}
$html .= "</div>";
}
return $html ?? '-';
})
->editColumn('link', function (Gallery $gallery) {
return $gallery->link ?? '-';
})
->editColumn('category_id', function (Gallery $gallery) {
return $gallery->category?->title ?? '-';
})
->editColumn('status', function (Gallery $gallery) {
$status = $gallery->status ? 'Published' : 'Draft';
$color = $gallery->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::gallery.datatable.action')
->rawColumns(['images', 'action', 'status'])
->toJson();
}
return view('ccms::gallery.index', [
'gallery' => $gallery,
'title' => $isEditing ? 'Edit Gallery' : 'Add Gallery',
'editable' => $isEditing ? true : false,
'categoryOptions' => $categoryOptions,
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$isEditing = $request->has('id');
$request->merge([
'slug' => Str::slug($request->title),
]);
if ($isEditing) {
$validated = $request->validate([
'title' => ['required', 'string', 'max:255', 'unique:categories,title,' . $request->id],
'slug' => ['required', 'string'],
'link' => ['nullable', 'string'],
'images' => ['nullable', 'string'],
'category_id' => ['nullable', 'integer'],
]);
$gallery = $this->galleryService->updateGallery($request->id, galleryData: $validated);
flash()->success("Gallery for {$gallery->title} has been updated.");
return to_route('gallery.index');
}
$maxOrder = Gallery::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'order' => $order,
]);
$validated = $request->validate([
'title' => ['required', 'string', 'unique:galleries,title'],
'slug' => ['required', 'string'],
'link' => ['nullable', 'string'],
'images' => ['nullable', 'string'],
'category_id' => ['nullable', 'integer'],
'order' => ['integer'],
]);
$gallery = $this->galleryService->storeGallery($validated);
flash()->success("Gallery for {$gallery->title} has been created.");
return to_route('gallery.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$gallery = $this->galleryService->getGalleryById($id);
return view('ccms::gallery.edit', [
'gallery' => $gallery,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
$gallery = $this->galleryService->deleteGallery($id);
return response()->json(['status' => 200, 'message' => "Gallery has been deleted."], 200);
}
public function reorder(Request $request)
{
$galleries = $this->galleryService->getAllGalleries();
foreach ($galleries as $gallery) {
foreach ($request->order as $order) {
if ($order['id'] == $gallery->id) {
$gallery->update(['order' => $order['position']]);
}
}
}
return response(['status' => true, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$gallery = Gallery::findOrFail($id);
$gallery->update(['status' => !$gallery->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}

View File

@@ -0,0 +1,195 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Modules\CCMS\Models\Country;
use Modules\CCMS\Models\Institution;
use Modules\CCMS\Services\InstitutionService;
use Yajra\DataTables\Facades\DataTables;
class InstitutionController extends Controller
{
protected $institutionService;
public function __construct(InstitutionService $institutionService)
{
$this->institutionService = $institutionService;
}
/**
* Display a listing of the resource.
*/
public function index(?int $id = null)
{
$countryOptions = Country::where('status', 1)->pluck('title', 'id');
$isEditing = !is_null($id);
$institution = $isEditing ? $this->institutionService->getInstitutionById($id) : null;
if (request()->ajax()) {
$model = Institution::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('country_id', function (Institution $institution) {
return $institution->country?->title ?? '-';
})
->editColumn('link', function (Institution $institution) {
return $institution->link ?? '-';
})
->editColumn('image', function (Institution $institution) {
return $institution->getRawOriginal('image') ? "<img src='{$institution->image}' alt='{$institution->title}' class='rounded avatar-sm material-shadow ms-2 img-thumbnail'>" : '-';
})
->editColumn('status', function (Institution $institution) {
$status = $institution->status ? 'Published' : 'Draft';
$color = $institution->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::institution.datatable.action')
->rawColumns(['image', 'action', 'status'])
->toJson();
}
return view('ccms::institution.index', [
'institution' => $institution,
'editable' => $isEditing ? true : false,
'title' => $isEditing ? 'Edit Institution' : 'Add Institution',
'countryOptions' => $countryOptions,
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$isEditing = $request->has('id');
$request->merge([
'slug' => Str::slug($request->title),
]);
if ($isEditing) {
$validated = $request->validate([
'title' => ['required', 'string', 'max:255', 'unique:institutions,title,' . $request->id],
'slug' => ['required', 'string'],
'link' => ['nullable'],
'image' => ['nullable', 'string'],
'location' => ['nullable', 'string'],
'country_id' => ['nullable', 'integer']
]);
$institution = $this->institutionService->updateInstitution($request->id, institutionData: $validated);
flash()->success("Institution for {$institution->title} has been updated.");
return to_route('institution.index');
}
$maxOrder = Institution::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'order' => $order,
]);
$validated = $request->validate([
'title' => ['required', 'string', 'unique:institutions,title'],
'slug' => ['required', 'string'],
'link' => ['nullable'],
'location' => ['nullable'],
'image' => ['nullable', 'string'],
'order' => ['integer'],
'country_id' => ['nullable', 'integer']
]);
$institution = $this->institutionService->storeInstitution($validated);
flash()->success("Institution for {$institution->title} has been created.");
return to_route('institution.index');
}
/**
* 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)
{
$institution = $this->institutionService->deleteInstitution($id);
return response()->json(['status' => 200, 'message' => "Institution has been deleted."], 200);
}
public function reorder(Request $request)
{
$institutions = $this->institutionService->getAllCategories();
foreach ($institutions as $institution) {
foreach ($request->order as $order) {
if ($order['id'] == $institution->id) {
$institution->update(['order' => $order['position']]);
}
}
}
return response(['status' => true, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$institution = Institution::findOrFail($id);
$institution->update(['status' => !$institution->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
public function getInstitutionsByCountry(Request $request)
{
try {
$institutions = Institution::where(['country_id' => $request->country_id])
->select('id', 'status', 'title')
->get();
return response()->json([
'status' => true,
'data' => $institutions,
'msg' => 'Fetch',
], 200);
} catch (\Throwable $th) {
return response()->json([
'status' => false,
'msg' => $th->getMessage(),
], 500);
}
}
}

View File

@@ -0,0 +1,219 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
use Modules\CCMS\Models\Page;
use Yajra\DataTables\Facades\DataTables;
class PageController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
$parentPages = Page::where(['status' => 1, 'type' => 'page'])->with("children")->get();
if ($request->ajax()) {
if ($request->filled("page_id")) {
$parentPage = Page::with('children')->find($request->get('page_id'));
$pages = collect([]);
if ($parentPage) {
$pages = collect([$parentPage])->merge($parentPage->children);
}
} else {
$pages = Page::orderBy('order')->get();
}
return DataTables::collection($pages)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('type', function ($page) {
return config("constants.page_type_options")[$page->type] ?? '-';
})
->editColumn('date', function ($page) {
return getFormatted(date: $page->date) ?? '-';
})
->editColumn('image', function (Page $page) {
return $page->getRawOriginal('image')
? "<img src='{$page->image}' alt='{$page->title}' class='rounded avatar-sm material-shadow ms-2 img-thumbnail'>"
: '-';
})
->addColumn('parents', function (Page $page) {
if ($page->parents->isEmpty()) {
return '-';
}
return $page->parents->map(function ($parent) {
return "<span class='badge bg-primary p-1'>{$parent->title}</span>";
})->implode(' ');
})
->editColumn('status', function (Page $page) {
$status = $page->status ? 'Published' : 'Draft';
$color = $page->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::page.datatable.action')
->rawColumns(['parents', 'image', 'status', 'action'])
->toJson();
}
return view('ccms::page.index', [
'title' => 'Page List',
'parentPages' => $parentPages,
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$isEditing = $request->has('id');
if ($isEditing) {
$page = Page::findOrFail($request->id);
} else {
$maxOrder = Page::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->merge([
'order' => $order,
'status' => 0,
'slug' => $request->title == 'Homepage' ? '/' : Str::slug($request->title),
]);
}
$validated = $request->validate([
'title' => [
'required',
'string',
'max:255',
Rule::unique('pages', 'title')->ignore($isEditing ? $request->id : null),
],
'type' => ['required', 'string'],
'order' => ['nullable', 'integer'],
'section' => ['nullable', 'array'],
'slug' => ['nullable', 'string'],
'status' => ['nullable', 'integer'],
], [
'title.unique' => 'Page already exists!',
]);
if ($isEditing) {
$page->update($validated);
} else {
$page = Page::create($validated);
}
$message = $isEditing ? "Page setting for {$page->title} has been updated." : "Page setting for {$page->title} has been created.";
flash()->success($message);
return redirect()->back();
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('ccms::page.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$page = Page::findOrFail($id);
return view('ccms::page.partials._form', [
'editable' => true,
'page' => $page,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
//
}
public function editContent($id)
{
$pageOptions = Page::where(['status' => 1, 'type' => 'page'])->pluck('title', 'id');
$page = Page::findOrFail($id);
return view('ccms::page.content', [
'title' => 'Update Page Content',
'page' => $page,
'editable' => true,
'pageOptions' => $pageOptions,
]);
}
public function updateContent(Request $request, $id)
{
$validated = $request->validate([
'parent_id' => ['nullable', 'array'],
]);
$page = Page::findOrFail($id);
if (is_null($page->date) && $request->status == 1) {
$page->date = now()->format('Y-m-d');
}
DB::transaction(function () use ($page, $request) {
$page->update($request->all());
if ($request->parent_id) {
$page->parents()->sync($request->parent_id);
}
});
flash()->success("Page content for {$page->title} has been updated.");
return redirect()->back();
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
$page = Page::findOrFail($id);
$page->delete();
return response()->json(['status' => 200, 'message' => "Page has been deleted."], 200);
}
public function reorder(Request $request)
{
$pages = Page::all();
foreach ($pages as $page) {
foreach ($request->order as $order) {
if ($order['id'] == $page->id) {
$page->update(['order' => $order['position']]);
}
}
}
return response(['status' => true, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$page = Page::findOrFail($id);
$page->update(['status' => !$page->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}

View File

@@ -0,0 +1,161 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Modules\CCMS\Models\Partner;
use Modules\CCMS\Services\PartnerService;
use Yajra\DataTables\Facades\DataTables;
class PartnerController extends Controller
{
protected $partnerService;
public function __construct(PartnerService $partnerService)
{
$this->partnerService = $partnerService;
}
/**
* Display a listing of the resource.
*/
public function index(?int $id = null)
{
$isEditing = !is_null($id);
$partner = $isEditing ? $this->partnerService->getPartnerById($id) : null;
if (request()->ajax()) {
$model = Partner::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('image', function (Partner $partner) {
return $partner->getRawOriginal('image') ? "<img src='{$partner->image}' alt='{$partner->title}' class='rounded avatar-sm material-shadow ms-2 img-thumbnail'>" : '-';
})
->editColumn('status', function (Partner $partner) {
$status = $partner->status ? 'Published' : 'Draft';
$color = $partner->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::partner.datatable.action')
->rawColumns(['image', 'action', 'status'])
->toJson();
}
return view('ccms::partner.index', [
'partner' => $partner,
'editable' => $isEditing ? true : false,
'title' => $isEditing ? 'Edit Partner' : 'Add Partner',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$isEditing = $request->has('id');
$request->merge([
'slug' => Str::slug($request->title),
]);
if ($isEditing) {
$validated = $request->validate([
'title' => ['required', 'string', 'max:255', 'unique:partners,title,' . $request->id],
'slug' => ['required', 'string'],
'link' => ['nullable'],
'image' => ['nullable', 'string'],
]);
$partner = $this->partnerService->updatePartner($request->id, partnerData: $validated);
flash()->success("Partner for {$partner->title} has been updated.");
return to_route('partner.index');
}
$maxOrder = Partner::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'order' => $order,
]);
$validated = $request->validate([
'title' => ['required', 'string', 'unique:partners,title'],
'slug' => ['required', 'string'],
'link' => ['nullable'],
'image' => ['nullable', 'string'],
'order' => ['integer'],
]);
$partner = $this->partnerService->storePartner($validated);
flash()->success("Partner for {$partner->title} has been created.");
return to_route('partner.index');
}
/**
* 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)
{
$partner = $this->partnerService->deletePartner($id);
return response()->json(['status' => 200, 'message' => "Partner has been deleted."], 200);
}
public function reorder(Request $request)
{
$partners = $this->partnerService->getAllCategories();
foreach ($partners as $partner) {
foreach ($request->order as $order) {
if ($order['id'] == $partner->id) {
$partner->update(['order' => $order['position']]);
}
}
}
return response(['status' => true, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$partner = Partner::findOrFail($id);
$partner->update(['status' => !$partner->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}

View File

@@ -0,0 +1,184 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Modules\CCMS\Models\Popup;
use Yajra\DataTables\Facades\DataTables;
class PopupController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
if (request()->ajax()) {
$model = Popup::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('images', function (Popup $popup) {
$html = '<div clas="h-stack">';
foreach ($popup->images as $image) {
$html .= "<img src='{$image}' alt='{$popup->title}' class='rounded avatar-sm material-shadow ms-2 img-thumbnail'>";
}
$html .= "</div>";
return $html;
})
->editColumn('status', function (Popup $popup) {
$status = $popup->status ? 'Published' : 'Draft';
$color = $popup->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::popup.datatable.action')
->rawColumns(['status', 'images', 'action'])
->toJson();
}
return view('ccms::popup.index', [
'title' => 'Popup List',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('ccms::popup.create', [
'title' => 'Create Popup',
'editable' => false,
]);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$maxOrder = Popup::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'slug' => Str::slug($request->title),
'order' => $order,
]);
try {
$validated = $request->validate([
'title' => 'required',
]);
Popup::create($request->all());
flash()->success("Popup has been created!");
return redirect()->route('popup.index');
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage())->withInput();
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('ccms::popup.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$popup = Popup::findOrFail($id);
return view('ccms::popup.edit', [
'title' => 'Edit Popup',
'editable' => true,
'popup' => $popup,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
$request->mergeIfMissing([
'slug' => Str::slug($request->title),
]);
try {
$request->validate([
'title' => 'required',
]);
$popup = Popup::findOrFail($id);
$popup->update($request->all());
flash()->success("Popup has been updated!");
return redirect()->route('popup.index');
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage())->withInput();
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
DB::transaction(function () use ($id) {
$popup = Popup::findOrFail($id);
$popup->delete();
$higherOrders = Popup::where('id', '>', $id)->get();
if ($higherOrders) {
foreach ($higherOrders as $higherOrder) {
$higherOrder->order--;
$higherOrder->saveQuietly();
}
}
return response()->json(['status' => 200, 'message' => 'Popup has been deleted!']);
});
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage());
}
}
public function reorder(Request $request)
{
$popups = Popup::all();
foreach ($popups as $popup) {
foreach ($request->order as $order) {
if ($order['id'] == $popup->id) {
$popup->update(['order' => $order['position']]);
}
}
}
return response(['status' => 200, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$popup = Popup::findOrFail($id);
$popup->update(['status' => !$popup->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}

View File

@@ -0,0 +1,152 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Modules\CCMS\Models\Service;
use Yajra\DataTables\Facades\DataTables;
class ServiceController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
if (request()->ajax()) {
$model = Service::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('image', function (Service $service) {
return $service->getRawOriginal('image') ? "<img src='{$service->image}' alt='{$service->title}' class='rounded avatar-sm material-shadow ms-2 img-thumbnail'>" : '-';
})
->editColumn('parent_id', function (Service $service) {
return $service->parent ? "<span class='badge bg-primary p-1'>{$service->parent?->title}</span>" : '-';
})
->editColumn('status', function (Service $service) {
$status = $service->status ? 'Published' : 'Draft';
$color = $service->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::service.datatable.action')
->rawColumns(['parent_id','image', 'status', 'action'])
->toJson();
}
return view('ccms::service.index', [
'title' => 'Service List',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$serviceOptions = Service::where('status', 1)->pluck('title', 'id');
return view('ccms::service.create', [
'title' => 'Create Service',
'editable' => false,
'serviceOptions' => $serviceOptions
]);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$maxOrder = Service::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'slug' => Str::slug($request->title),
'order' => $order,
]);
try {
$validated = $request->validate([
'title' => 'required',
]);
Service::create($request->all());
flash()->success("Service has been created!");
return redirect()->route('service.index');
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage())->withInput();
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('ccms::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$serviceOptions = Service::where('status', 1)->pluck('title', 'id');
$service = Service::findOrFail($id);
return view('ccms::service.edit', [
'title' => 'Edit Service',
'editable' => true,
'service' => $service,
'serviceOptions' => $serviceOptions
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
$request->merge([
'slug' => Str::slug($request->title),
]);
$validated = $request->validate([]);
$service = Service::findOrFail($id);
$service->update($request->all());
flash()->success("Service has been updated.");
return redirect()->back();
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
$service = Service::findOrFail($id);
$service->delete();
return response()->json(['status' => 200, 'message' => "Service has been deleted."], 200);
}
public function reorder(Request $request)
{
$services = Service::all();
foreach ($services as $service) {
foreach ($request->order as $order) {
if ($order['id'] == $service->id) {
$service->update(['order' => $order['position']]);
}
}
}
return response(['status' => true, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$service = Service::findOrFail($id);
$service->update(['status' => !$service->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
use Modules\CCMS\Models\Setting;
class SettingController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
return view('ccms::setting.index', [
'editable' => true,
'title' => 'Edit Setting',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$request->mergeIfMissing([
'enable_reCaptcha' => 0,
]);
$input = $request->except(['_token', '_method']);
foreach ($input as $key => $value) {
Setting::updateOrCreate(
['key' => $key],
['value' => $value]
);
}
Cache::forget('setting');
return to_route('setting.index')->with('success', 'Setting have been updated!');
}
/**
* 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)
{
//
}
}

View File

@@ -0,0 +1,187 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Modules\CCMS\Models\Slider;
use Yajra\DataTables\Facades\DataTables;
class SliderController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
if (request()->ajax()) {
$model = Slider::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('images', function (Slider $slider) {
if (!isEmptyArray($slider->images)) {
$html = '<div clas="h-stack">';
foreach ($slider->images as $image) {
$html .= "<img src='{$image}' alt='{$slider->title}' class='rounded avatar-sm material-shadow ms-2 img-thumbnail'>";
}
$html .= "</div>";
}
return $html ?? '-';
})
->editColumn('status', function (Slider $slider) {
$status = $slider->status ? 'Published' : 'Draft';
$color = $slider->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::slider.datatable.action')
->rawColumns(['status', 'images', 'action'])
->toJson();
}
return view('ccms::slider.index', [
'title' => 'Slider List',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('ccms::slider.create', [
'title' => 'Create Slider',
'editable' => false,
]);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$maxOrder = Slider::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'slug' => Str::slug($request->title),
'order' => $order,
]);
try {
$validated = $request->validate([
'title' => 'required',
]);
Slider::create($request->all());
flash()->success("Slider has been created!");
return redirect()->route('slider.index');
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage())->withInput();
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('ccms::slider.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$slider = Slider::findOrFail($id);
return view('ccms::slider.edit', [
'title' => 'Edit Slider',
'editable' => true,
'slider' => $slider,
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
$request->mergeIfMissing([
'slug' => Str::slug($request->title),
]);
try {
$request->validate([
'title' => 'required',
]);
$slider = Slider::findOrFail($id);
$slider->update($request->all());
flash()->success("Slider has been updated!");
return redirect()->route('slider.index');
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage())->withInput();
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
DB::transaction(function () use ($id) {
$slider = Slider::findOrFail($id);
$slider->delete();
$higherOrders = Slider::where('id', '>', $id)->get();
if ($higherOrders) {
foreach ($higherOrders as $higherOrder) {
$higherOrder->order--;
$higherOrder->saveQuietly();
}
}
return response()->json(['status' => 200, 'message' => 'Slider has been deleted!']);
});
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage());
}
}
public function reorder(Request $request)
{
$sliders = Slider::all();
foreach ($sliders as $slider) {
foreach ($request->order as $order) {
if ($order['id'] == $slider->id) {
$slider->update(['order' => $order['position']]);
}
}
}
return response(['status' => 200, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$slider = Slider::findOrFail($id);
$slider->update(['status' => !$slider->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}

View File

@@ -0,0 +1,185 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Modules\CCMS\Models\Branch;
use Modules\CCMS\Models\Team;
use Yajra\DataTables\Facades\DataTables;
class TeamController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
if (request()->ajax()) {
$model = Team::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('image', function (Team $team) {
return $team->getRawOriginal('image') ? "<img src='{$team->image}' alt='{$team->title}' class='rounded avatar-sm material-shadow ms-2 img-thumbnail'>" : '-';
})
->editColumn('status', function (Team $team) {
$status = $team->status ? 'Published' : 'Draft';
$color = $team->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::team.datatable.action')
->rawColumns(['status', 'image', 'action'])
->toJson();
}
return view('ccms::team.index', [
'title' => 'Team List',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$branchOptions = Branch::where('status', 1)->pluck('title', 'id');
return view('ccms::team.create', [
'title' => 'Create Team',
'editable' => false,
'branchOptions' => $branchOptions
]);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$maxOrder = Team::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'slug' => Str::slug($request->title),
'order' => $order,
]);
try {
$validated = $request->validate([
'title' => 'required',
]);
Team::create($request->all());
flash()->success("Team has been created!");
return redirect()->route('team.index');
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage())->withInput();
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('ccms::team.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$branchOptions = Branch::where('status', 1)->pluck('title', 'id');
$team = Team::findOrFail($id);
return view('ccms::team.edit', [
'title' => 'Edit Team',
'editable' => true,
'team' => $team,
'branchOptions' => $branchOptions
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
$request->mergeIfMissing([
'slug' => Str::slug($request->title),
]);
try {
$request->validate([
'title' => 'required',
]);
$team = Team::findOrFail($id);
$team->update($request->all());
flash()->success("Team has been updated!");
return redirect()->route('team.index');
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage())->withInput();
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
DB::transaction(function () use ($id) {
$team = Team::findOrFail($id);
$team->delete();
$higherOrders = Team::where('id', '>', $id)->get();
if ($higherOrders) {
foreach ($higherOrders as $higherOrder) {
$higherOrder->order--;
$higherOrder->saveQuietly();
}
}
return response()->json(['status' => 200, 'message' => 'Team has been deleted!']);
});
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage());
}
}
public function reorder(Request $request)
{
$teams = Team::all();
foreach ($teams as $team) {
foreach ($request->order as $order) {
if ($order['id'] == $team->id) {
$team->update(['order' => $order['position']]);
}
}
}
return response(['status' => 200, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$team = Team::findOrFail($id);
$team->update(['status' => !$team->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}

View File

@@ -0,0 +1,153 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Modules\CCMS\Models\Test;
use Yajra\DataTables\Facades\DataTables;
class TestController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
if (request()->ajax()) {
$model = Test::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('image', function (Test $test) {
return $test->getRawOriginal('image') ? "<img src='{$test->image}' alt='{$test->title}' class='rounded avatar-sm material-shadow ms-2 img-thumbnail'>" : '-';
})
->editColumn('parent_id', function (Test $test) {
return $test->parent ? "<span class='badge bg-primary p-1'>{$test->parent?->title}</span>" : '-';
})
->editColumn('status', function (Test $test) {
$status = $test->status ? 'Published' : 'Draft';
$color = $test->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::test.datatable.action')
->rawColumns(['parent_id','image', 'status', 'action'])
->toJson();
}
return view('ccms::test.index', [
'title' => 'Test List',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$testOptions = Test::where('status', 1)
->pluck('title', 'id');
return view('ccms::test.create', [
'title' => 'Create Test',
'editable' => false,
'testOptions' => $testOptions
]);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$maxOrder = Test::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'slug' => Str::slug($request->title),
'order' => $order,
]);
try {
$validated = $request->validate([
'title' => 'required',
]);
Test::create($request->all());
flash()->success("Test has been created!");
return redirect()->route('test.index');
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage())->withInput();
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('ccms::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$testOptions = Test::where('status', 1)->pluck('title', 'id');
$test = Test::findOrFail($id);
return view('ccms::test.edit', [
'title' => 'Edit Test',
'editable' => true,
'test' => $test,
'testOptions' => $testOptions
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
$request->merge([
'slug' => Str::slug($request->title),
]);
$validated = $request->validate([]);
$test = Test::findOrFail($id);
$test->update($request->all());
flash()->success("Test has been updated.");
return redirect()->back();
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
$test = Test::findOrFail($id);
$test->delete();
return response()->json(['status' => 200, 'message' => "Test has been deleted."], 200);
}
public function reorder(Request $request)
{
$tests = Test::all();
foreach ($tests as $test) {
foreach ($request->order as $order) {
if ($order['id'] == $test->id) {
$test->update(['order' => $order['position']]);
}
}
}
return response(['status' => true, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$test = Test::findOrFail($id);
$test->update(['status' => !$test->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}

View File

@@ -0,0 +1,184 @@
<?php
namespace Modules\CCMS\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Modules\CCMS\Models\Branch;
use Modules\CCMS\Models\Testimonial;
use Yajra\DataTables\Facades\DataTables;
class TestimonialController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
if (request()->ajax()) {
$model = Testimonial::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('image', function (Testimonial $testimonial) {
return $testimonial->getRawOriginal('image') ? "<img src='{$testimonial->image}' alt='{$testimonial->title}' class='rounded avatar-sm material-shadow ms-2 img-thumbnail'>" : '-';
})
->editColumn('status', function (Testimonial $testimonial) {
$status = $testimonial->status ? 'Published' : 'Draft';
$color = $testimonial->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'ccms::testimonial.datatable.action')
->rawColumns(['status', 'image', 'action'])
->toJson();
}
return view('ccms::testimonial.index', [
'title' => 'Testimonial List',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$branchOptions = Branch::where('status', 1)->pluck('title', 'id');
return view('ccms::testimonial.create', [
'title' => 'Create Testimonial',
'editable' => false,
'branchOptions' => $branchOptions
]);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$maxOrder = Testimonial::max('order');
$order = $maxOrder ? ++$maxOrder : 1;
$request->mergeIfMissing([
'slug' => Str::slug($request->title),
'order' => $order,
]);
try {
$validated = $request->validate([
'title' => 'required',
]);
Testimonial::create($request->all());
flash()->success("Testimonial has been created!");
return redirect()->route('testimonial.index');
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage())->withInput();
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('ccms::testimonial.show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$branchOptions = Branch::where('status', 1)->pluck('title', 'id');
$testimonial = Testimonial::findOrFail($id);
return view('ccms::testimonial.edit', [
'title' => 'Edit Testimonial',
'editable' => true,
'testimonial' => $testimonial,
'branchOptions' => $branchOptions
]);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
$request->mergeIfMissing([
'slug' => Str::slug($request->title),
]);
try {
$request->validate([
'title' => 'required',
]);
$testimonial = Testimonial::findOrFail($id);
$testimonial->update($request->all());
flash()->success("Testimonial has been updated!");
return redirect()->route('testimonial.index');
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage())->withInput();
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
DB::transaction(function () use ($id) {
$testimonial = Testimonial::findOrFail($id);
$testimonial->delete();
$higherOrders = Testimonial::where('id', '>', $id)->get();
if ($higherOrders) {
foreach ($higherOrders as $higherOrder) {
$higherOrder->order--;
$higherOrder->saveQuietly();
}
}
return response()->json(['status' => 200, 'message' => 'Testimonial has been deleted!']);
});
} catch (\Throwable $th) {
return redirect()->back()->with('error', $th->getMessage());
}
}
public function reorder(Request $request)
{
$testimonials = Testimonial::all();
foreach ($testimonials as $testimonial) {
foreach ($request->order as $order) {
if ($order['id'] == $testimonial->id) {
$testimonial->update(['order' => $order['position']]);
}
}
}
return response(['status' => 200, 'message' => 'Reordered successfully'], 200);
}
public function toggle($id)
{
$testimonial = Testimonial::findOrFail($id);
$testimonial->update(['status' => !$testimonial->status]);
return response(['status' => 200, 'message' => 'Toggled successfully'], 200);
}
}