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,34 @@
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Modules\User\Repositories\PermissionRepository;
use Modules\User\Services\PermissionService;
class GeneratePermissions extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'permissions:generate';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Generate Permissions using Named Route';
/**
* Execute the console command.
*/
public function handle()
{
$this->info('Generating Permissions');
PermissionService::generatePermissionFromRoutes();
$this->info('Permissions have been generated!');
}
}

163
app/Helpers/Helper.php Normal file
View File

@@ -0,0 +1,163 @@
<?php
use Carbon\Carbon;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Modules\CCMS\Models\Setting;
if (!function_exists('setting')) {
function setting($key = null)
{
$setting = Cache::has('setting') ? Cache::get('setting') : Cache::rememberForever('setting', function () {
return Setting::get()->mapWithKeys(function (Setting $setting) {
return [$setting->key => $setting->value];
})->toArray();
});
return array_key_exists($key, $setting) ? $setting[$key] : null;
}
}
if (!function_exists('uploadImage')) {
function uploadImage($file, $path = 'uploads')
{
$fileName = uniqid() . '.' . $file->getClientOriginalExtension();
$filePath = Storage::disk('public')->putFileAs($path, $file, $fileName);
return $filePath;
}
}
function getPageTemplateOptions()
{
$client = config('app.client');
$pageTemplateOptions = collect(File::files(resource_path("views/client/{$client}/pages")))
->mapWithKeys(function ($file) {
$template = Str::replace('.blade.php', '', $file->getFilename());
return [
$template => $template,
];
});
return $pageTemplateOptions->all();
}
if (!function_exists('getFormatted')) {
function getFormatted($dateTime = null, $date = null, $time = null, $format = null)
{
$data = null;
switch (true) {
case !is_null($dateTime):
$data = $dateTime;
$format ??= 'd M, Y h:i A';
break;
case !is_null($date) && !is_null($time):
$data = "{$date} {$time}";
$format ??= 'd M, Y h:i A';
break;
case !is_null($date):
$data = $date;
$format ??= 'd M, Y';
break;
case !is_null($time):
$data = $time;
$format ??= 'h:i A';
break;
default:
return null;
}
try {
$formatted = Carbon::parse($data)->format($format);
return $formatted;
} catch (\Exception $e) {
return null;
}
}
function getThemeColor($lightenFactor = 0.3)
{
$themeColor = setting('color') ?? '#be2400';
if (!preg_match('/^#[a-fA-F0-9]{6}$/', $themeColor)) {
return $themeColor;
}
$lighterColor = lightenColor($themeColor, $lightenFactor);
return [
'original' => $themeColor,
'lighter' => $lighterColor,
];
}
/**
* Lighten a hexadecimal color.
*
* @param string $hexColor
* @param float $factor
* @return string
*/
function lightenColor(string $hexColor, float $factor = 0.2): string
{
$hexColor = ltrim($hexColor, '#');
// Convert hex to RGB
$r = hexdec(substr($hexColor, 0, 2));
$g = hexdec(substr($hexColor, 2, 2));
$b = hexdec(substr($hexColor, 4, 2));
// Apply the lightening factor
$r = min(255, (int) ($r + (255 - $r) * $factor));
$g = min(255, (int) ($g + (255 - $g) * $factor));
$b = min(255, (int) ($b + (255 - $b) * $factor));
// Convert back to hex
return sprintf('#%02x%02x%02x', $r, $g, $b);
}
function setEnvIfNotExists($key, $value)
{
$envFile = app()->environmentFilePath(); // Path to the .env file
$str = file_get_contents($envFile);
// Check if the key exists in the .env file
$keyExists = preg_match("/^{$key}=.*/m", $str);
if (!$keyExists) {
// If the key doesn't exist, append it to the .env file
$str .= "\n{$key}={$value}";
file_put_contents($envFile, $str);
}
}
function isEmptyArray($array = [])
{
return is_array($array) && array_filter($array) === [];
}
if (!function_exists('sendNotification')) {
function sendNotification($user, $notification = [])
{
Notification::send($user, new App\Notifications\SendNotification($notification));
}
}
if (!function_exists('uploadImage')) {
function uploadImage($file, $path = 'uploads')
{
$fileName = time() . '_' . $file->getClientOriginalName();
$filePath = Storage::disk('public')->putFileAs($path, $file, $fileName);
return $filePath;
}
}
}

268
app/Helpers/QueryHelper.php Normal file
View File

@@ -0,0 +1,268 @@
<?php
use Modules\CCMS\Models\Blog;
use Modules\CCMS\Models\Category;
use Modules\CCMS\Models\Counter;
use Modules\CCMS\Models\Country;
use Modules\CCMS\Models\Faq;
use Modules\CCMS\Models\FaqCategory;
use Modules\CCMS\Models\Gallery;
use Modules\CCMS\Models\GalleryCategory;
use Modules\CCMS\Models\Institution;
use Modules\CCMS\Models\Page;
use Modules\CCMS\Models\Partner;
use Modules\CCMS\Models\Service;
use Modules\CCMS\Models\Slider;
use Modules\CCMS\Models\Team;
use Modules\CCMS\Models\Test;
use Modules\CCMS\Models\Testimonial;
use Modules\Menu\Models\Menu;
function getSliders(?int $limit = null, ?string $order = 'desc')
{
return Slider::query()
->where('status', 1)
->orderBy('order', $order)
->when($limit, function ($query) use ($limit) {
$query->limit($limit);
})
->get();
}
function getBlogCategories(?int $limit = null, ?string $order = 'desc')
{
return Category::query()
->where('status', 1)
->orderBy('order', $order)
->when($limit, function ($query) use ($limit) {
$query->limit($limit);
})
->get();
}
function getFAQs(?int $limit = null, ?string $order = 'desc')
{
return Faq::query()
->where('status', 1)
->orderBy('order', $order)
->when($limit, function ($query) use ($limit) {
$query->limit($limit);
})
->get();
}
function getTeams(?int $limit = null, ?string $order = 'desc')
{
return Team::query()
->where('status', 1)
->orderBy('order', $order)
->when($limit, function ($query) use ($limit) {
$query->limit($limit);
})
->get();
}
function getTestimonials(?int $limit = null, ?string $order = 'desc')
{
return Testimonial::query()
->where('status', 1)
->orderBy('order', $order)
->when($limit, function ($query) use ($limit) {
$query->limit($limit);
})
->get();
}
function getPartners(?int $limit = null, ?string $order = 'desc', bool $paginate = false)
{
$query = Partner::query()
->where('status', 1)
->orderBy('order', $order);
if ($limit && $paginate) {
return $query->paginate($limit);
} elseif ($limit && !$paginate) {
return $query->limit($limit)->get();
} else {
return $query->get();
}
}
function getGalleries(?int $limit = null, ?string $order = 'desc', bool $paginate = false)
{
$query = Gallery::query()
->where('status', 1)
->orderBy('order', $order);
if ($limit && $paginate) {
return $query->paginate($limit);
} elseif ($limit && !$paginate) {
return $query->limit($limit)->get();
} else {
return $query->get();
}
}
function getBlogs(?int $limit = null, ?string $order = 'desc', bool $paginate = false)
{
$query = Blog::query()
->where('status', 1)
->orderBy('order', $order);
if ($limit && $paginate) {
return $query->paginate($limit);
} elseif ($limit && !$paginate) {
return $query->limit($limit)->get();
} else {
return $query->get();
}
}
function getBlogBySlug(?string $slug)
{
return Blog::query()
->where('status', 1)
->where('slug', $slug)
->first();
}
function getCounters($limit = null, $order = 'desc')
{
return Counter::query()
->where('status', 1)
->orderBy('order', $order)
->when($limit, function ($query) use ($limit) {
$query->limit($limit);
})
->get();
}
function getServices($limit = null, $order = 'desc')
{
return Service::query()
->where('status', 1)
->where('parent_id', null)
->orderBy('order', $order)
->when($limit, function ($query) use ($limit) {
$query->limit($limit);
})
->get();
}
function getInstitutions($limit = null, $order = 'desc')
{
return Institution::query()
->where('status', 1)
->orderBy('order', $order)
->when($limit, function ($query) use ($limit) {
$query->limit($limit);
})
->get();
}
function getClasses($limit = null, $order = 'desc')
{
return Test::query()
->where('status', 1)
->where('parent_id', null)
->orderBy('order', $order)
->when($limit, function ($query) use ($limit) {
$query->limit($limit);
})
->get();
}
function getDestinations($limit = null, $order = 'desc')
{
return Country::query()
->where('status', 1)
->orderBy('order', $order)
->when($limit, function ($query) use ($limit) {
$query->limit($limit);
})
->get();
}
function getGalleriesByCategory(?int $limit = null, ?string $order = 'desc', ?string $category = null)
{
return GalleryCategory::query()
->where('status', 1)
->where('slug', $category)
->with('galleries', function ($query) use ($limit, $order) {
$query->where('status', 1)
->orderBy('order', $order)
->when($limit, function ($query) use ($limit) {
$query->limit($limit);
});
})
->first();
}
function getInstitutionsByCountry(?int $limit = null, ?string $order = 'desc', ?string $country = null)
{
return Country::query()
->where('status', 1)
->where('slug', $country)
->with('institutions', function ($query) use ($limit, $order) {
$query->where('status', 1)
->orderBy('order', $order)
->when($limit, function ($query) use ($limit) {
$query->limit($limit);
});
})
->first();
}
function getFAQsByCategory(?int $limit = null, ?string $order = 'desc', ?string $category = null)
{
return FaqCategory::query()
->where('status', 1)
->where('slug', $category)
->with('faqs', function ($query) use ($limit, $order) {
$query->where('status', 1)
->orderBy('order', $order)
->when($limit, function ($query) use ($limit) {
$query->limit($limit);
});
})
->first();
}
function getPageWithChildrenBySlug(?string $parent, ?string $slug, ?int $limit = null, ?string $order = 'desc')
{
$page = Page::where([
'status' => 1,
'type' => 'page',
'slug' => $slug,
])
->when($parent, function ($query) use ($parent) {
$query->where('parent', $parent);
})
->with(['children' => function ($query) use ($limit, $order) {
$query->orderBy('order', $order)
->when($limit, function ($query) use ($limit) {
$query->limit($limit);
});
}])
->first();
return $page;
}
function getAllHeaderMenusWithChildren()
{
$headerMenuItems = Menu::where(['menu_location_id' => 1, 'parent_id' => null, 'status' => 1])->with('children', function ($query) {
$query->where('status', 1)
->orderBy('order', 'asc');
})->orderBy('order', 'asc')->get();
return $headerMenuItems;
}
function getAllFooterMenusWithChildren()
{
$footerMenuItems = Menu::where(['menu_location_id' => 2, 'parent_id' => null, 'status' => 1])->with('children', function ($query) {
$query->orderBy('order', 'asc');
})->orderBy('order', 'asc')->get();
return $footerMenuItems;
}

View File

@@ -0,0 +1,61 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\LoginRequest;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
use Illuminate\View\View;
class AuthenticatedSessionController extends Controller
{
/**
* Display the login view.
*/
public function create(): View
{
return view('auth.login');
}
/**
* Handle an incoming authentication request.
*/
public function store(LoginRequest $request): RedirectResponse
{
$request->authenticate();
$user = Auth::user();
if (!$user || !$user->canLogin()) {
Auth::logout();
throw ValidationException::withMessages([
'email' => $user && !$user->canLogin()
? __('auth.account_disabled')
: __('auth.failed'),
]);
}
$request->session()->regenerate();
return redirect()->intended(route('dashboard', absolute: false));
}
/**
* Destroy an authenticated session.
*/
public function destroy(Request $request): RedirectResponse
{
Auth::guard('web')->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return redirect('/');
}
}

View File

@@ -0,0 +1,40 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
use Illuminate\View\View;
class ConfirmablePasswordController extends Controller
{
/**
* Show the confirm password view.
*/
public function show(): View
{
return view('auth.confirm-password');
}
/**
* Confirm the user's password.
*/
public function store(Request $request): RedirectResponse
{
if (! Auth::guard('web')->validate([
'email' => $request->user()->email,
'password' => $request->password,
])) {
throw ValidationException::withMessages([
'password' => __('auth.password'),
]);
}
$request->session()->put('auth.password_confirmed_at', time());
return redirect()->intended(route('dashboard', absolute: false));
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
class EmailVerificationNotificationController extends Controller
{
/**
* Send a new email verification notification.
*/
public function store(Request $request): RedirectResponse
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(route('dashboard', absolute: false));
}
$request->user()->sendEmailVerificationNotification();
return back()->with('status', 'verification-link-sent');
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
class EmailVerificationPromptController extends Controller
{
/**
* Display the email verification prompt.
*/
public function __invoke(Request $request): RedirectResponse|View
{
return $request->user()->hasVerifiedEmail()
? redirect()->intended(route('dashboard', absolute: false))
: view('auth.verify-email');
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Auth\Events\PasswordReset;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Str;
use Illuminate\Validation\Rules;
use Illuminate\View\View;
class NewPasswordController extends Controller
{
/**
* Display the password reset view.
*/
public function create(Request $request): View
{
return view('auth.reset-password', ['request' => $request]);
}
/**
* Handle an incoming new password request.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function store(Request $request): RedirectResponse
{
$request->validate([
'token' => ['required'],
'email' => ['required', 'email'],
'password' => ['required', 'confirmed', Rules\Password::defaults()],
]);
// Here we will attempt to reset the user's password. If it is successful we
// will update the password on an actual user model and persist it to the
// database. Otherwise we will parse the error and return the response.
$status = Password::reset(
$request->only('email', 'password', 'password_confirmation', 'token'),
function ($user) use ($request) {
$user->forceFill([
'password' => Hash::make($request->password),
'remember_token' => Str::random(60),
])->save();
event(new PasswordReset($user));
}
);
// If the password was successfully reset, we will redirect the user back to
// the application's home authenticated view. If there is an error we can
// redirect them back to where they came from with their error message.
return $status == Password::PASSWORD_RESET
? redirect()->route('login')->with('status', __($status))
: back()->withInput($request->only('email'))
->withErrors(['email' => __($status)]);
}
}

View File

@@ -0,0 +1,29 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules\Password;
class PasswordController extends Controller
{
/**
* Update the user's password.
*/
public function update(Request $request): RedirectResponse
{
$validated = $request->validateWithBag('updatePassword', [
'current_password' => ['required', 'current_password'],
'password' => ['required', Password::defaults(), 'confirmed'],
]);
$request->user()->update([
'password' => Hash::make($validated['password']),
]);
return back()->with('status', 'password-updated');
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Password;
use Illuminate\View\View;
class PasswordResetLinkController extends Controller
{
/**
* Display the password reset link request view.
*/
public function create(): View
{
return view('auth.forgot-password');
}
/**
* Handle an incoming password reset link request.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function store(Request $request): RedirectResponse
{
$request->validate([
'email' => ['required', 'email'],
]);
// We will send the password reset link to this user. Once we have attempted
// to send the link, we will examine the response then see the message we
// need to show to the user. Finally, we'll send out a proper response.
$status = Password::sendResetLink(
$request->only('email')
);
return $status == Password::RESET_LINK_SENT
? back()->with('status', __($status))
: back()->withInput($request->only('email'))
->withErrors(['email' => __($status)]);
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Auth\Events\Registered;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules;
use Illuminate\View\View;
class RegisteredUserController extends Controller
{
/**
* Display the registration view.
*/
public function create(): View
{
return view('auth.register');
}
/**
* Handle an incoming registration request.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function store(Request $request): RedirectResponse
{
$request->validate([
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
'password' => ['required', 'confirmed', Rules\Password::defaults()],
]);
$user = User::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
event(new Registered($user));
Auth::login($user);
return redirect(route('dashboard', absolute: false));
}
}

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Auth\EmailVerificationRequest;
use Illuminate\Http\RedirectResponse;
class VerifyEmailController extends Controller
{
/**
* Mark the authenticated user's email address as verified.
*/
public function __invoke(EmailVerificationRequest $request): RedirectResponse
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
}
if ($request->user()->markEmailAsVerified()) {
event(new Verified($request->user()));
}
return redirect()->intended(route('dashboard', absolute: false).'?verified=1');
}
}

View File

@@ -0,0 +1,141 @@
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Modules\Client\Interfaces\ClientInterface;
use Modules\Content\Interfaces\ContentInterface;
use Modules\Content\Models\Content;
use Modules\Meeting\Models\Event;
use Modules\Meeting\Models\Meeting;
use Modules\Meeting\Repositories\EventInterface;
use Modules\Meeting\Repositories\MeetingInterface;
use Modules\Product\Interfaces\ProductInterface;
class CalendarController extends Controller
{
private $event;
private $content;
private $meeting;
private $employee;
private $client;
private $product;
public function __construct(
EventInterface $event,
MeetingInterface $meeting,
ContentInterface $content,
ProductInterface $product,
ClientInterface $client
) {
$this->event = $event;
$this->meeting = $meeting;
$this->content = $content;
$this->client = $client;
$this->product = $product;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Calendar';
$data['events'] = $this->event->findAll();
$data['meetings'] = $this->meeting->findAll();
$data['contents'] = $this->content->findAllUpcomingScheduledContent();
$data['productOptions'] = $this->product->pluck();
$data['clientList'] = $this->client->pluck();
return view('calendar.index', $data);
}
public function calendarByAjax(Request $request)
{
$filters['start_date'] = $request->start;
$filters['end_date'] = $request->end;
$filters['product_id'] = $request->product_id;
$list = [];
$events = Event::when($filters, function ($query) use ($filters) {
if (isset($filters["start_date"])) {
$query->whereDate("start_date", ">=", $filters["start_date"]);
}
if (isset($filters["end_date"])) {
$query->whereDate("end_date", "<=", $filters["end_date"]);
$query->orWhereNull("end_date");
}
})->get();
foreach ($events as $event) {
$list[] = [
"id" => $event->id,
"title" => $event->title,
"type" => 'event',
"start" => $event->start_date,
"end" => $event->end_date,
"className" => "bg-primary",
"desc" => $event->description,
"location" => $event->location,
'allDay' => true,
];
}
$contents = Content::where('status', '!=', 11)
->when($filters, function ($query) use ($filters) {
if (isset($filters["start_date"])) {
$query->whereDate("release_date", ">=", $filters["start_date"]);
}
if (isset($filters["end_date"])) {
$query->where(function ($q) use ($filters) {
$q->whereDate("release_date", "<=", $filters["end_date"])
->orWhereNull("release_date");
});
}
if (isset($filters["product_id"])) {
$query->where("product_id", $filters["product_id"]);
}
})
->with(['product.client'])
->get();
foreach ($contents as $content) {
$list[] = [
"id" => $content->id,
"title" => $content->title,
"type" => 'content schedule',
"start" => Carbon::parse($content->getRawOriginal('release_date') . ' ' . $content->getRawOriginal('release_time')),
"end" => null,
"className" => "bg-success",
"location" => null,
"desc" => $content->product?->client?->name,
'allDay' => false,
];
}
$meetings = Meeting::when($filters, function ($query) use ($filters) {
if (isset($filters["start_date"])) {
$query->whereDate("date", ">=", $filters["start_date"]);
}
})->get();
foreach ($meetings as $meeting) {
$list[] = [
"id" => $meeting->id,
"title" => $meeting->title,
"type" => 'meeting',
"start" => Carbon::parse($meeting->getRawOriginal('date') . ' ' . $meeting->getRawOriginal('start_time')),
"location" => $meeting->location,
"desc" => $meeting->description,
"className" => "bg-warning",
'allDay' => false,
];
}
return $list;
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace App\Http\Controllers;
abstract class Controller
{
//
}

View File

@@ -0,0 +1,63 @@
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Support\Facades\Session;
use Modules\CCMS\Models\Blog;
use Modules\CCMS\Models\Enquiry;
use Modules\CCMS\Models\Partner;
use Modules\CCMS\Models\Service;
use Modules\CCMS\Models\Team;
use Yajra\DataTables\Facades\DataTables;
class DashboardController extends Controller
{
public function dashboard()
{
return view('dashboard', [
'usersCount' => User::count(),
'blogsCount' => Blog::where('status', 1)->count(),
'teamsCount' => Team::where('status', 1)->count(),
'servicesCount' => Service::where('status', 1)->count(),
'partnersCount' => Partner::where('status', 1)->count(),
]);
}
public function getEnquiries()
{
if (request()->ajax()) {
$model = Enquiry::query()->where('is_read', 0)->latest();
return DataTables::eloquent($model)
->addIndexColumn()
->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();
}
}
public function toggleDashboard()
{
$validated = request()->validate([
'sidebar' => 'required|in:sidebar,cpm-sidebar',
])['sidebar'];
auth()->user()->update(['active_sidebar' => $validated]);
flash()->success("Dashboard has been toggled!");
return response()->json([
'status' => true,
'message' => 'Dashboard has been toggled!',
], 200);
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class NotificationController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
$data['notifications'] = auth()->user()->notifications;
return view('notification.index', $data);
}
public function markAsRead(Request $request)
{
$filterData = $request->all();
try {
$notification = auth()->user()->notifications()->where('id', $filterData['id'])->first();
if ($notification) {
$notification->markAsRead();
}
return redirect()->back()->withSuccess('Mark As Read');
} catch (\Throwable $th) {
return redirect()->back()->withError('Something Went Wrong!');
}
}
public function markAllAsRead(Request $request)
{
try {
foreach (auth()->user()->unreadNotifications as $notification) {
$notification->markAsRead();
}
return redirect()->back()->withSuccess('Mark All As Read');
} catch (\Throwable $th) {
//throw $th;
return redirect()->back()->withError('Something Went Wrong!');
}
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests\ProfileUpdateRequest;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Redirect;
use Illuminate\View\View;
class ProfileController extends Controller
{
/**
* Display the user's profile form.
*/
public function edit(Request $request): View
{
return view('profile.edit', [
'user' => $request->user(),
]);
}
/**
* Update the user's profile information.
*/
public function update(ProfileUpdateRequest $request): RedirectResponse
{
$request->user()->fill($request->validated());
if ($request->user()->isDirty('email')) {
$request->user()->email_verified_at = null;
}
$request->user()->save();
return Redirect::route('profile.edit')->with('status', 'profile-updated');
}
/**
* Delete the user's account.
*/
public function destroy(Request $request): RedirectResponse
{
$request->validateWithBag('userDeletion', [
'password' => ['required', 'current_password'],
]);
$user = $request->user();
Auth::logout();
$user->delete();
$request->session()->invalidate();
$request->session()->regenerateToken();
return Redirect::to('/');
}
}

View File

@@ -0,0 +1,224 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;
use Modules\CCMS\Models\Blog;
use Modules\CCMS\Models\Country;
use Modules\CCMS\Models\Institution;
use Modules\CCMS\Models\Page;
use Modules\CCMS\Models\Service;
use Modules\CCMS\Models\Test;
use Modules\CourseFinder\Models\Coop;
use Modules\CourseFinder\Models\Program;
use Modules\CourseFinder\Models\ProgramLevel;
use Modules\CourseFinder\Services\ProgramService;
class WebsiteController extends Controller
{
private $path;
protected $programService;
public function __construct(ProgramService $programService)
{
$this->programService = $programService;
$headerMenus = getAllHeaderMenusWithChildren();
$footerMenus = getAllFooterMenusWithChildren();
$tests = Test::where('status', 1)->where('parent_id', null)->get();
$countries = Country::where('status', 1)->where('parent_id', null)->get();
$services = Service::where('status', 1)->where('parent_id', null)->get();
$this->path = config('app.client');
view()->share([
'headerMenus' => $headerMenus,
'footerMenus' => $footerMenus,
'tests' => $tests,
'countries' => $countries,
'services' => $services,
]);
}
public function home()
{
$data['sliders'] = getSliders(limit: null, order: 'asc');
$data['counters'] = getCounters(limit: null, order: 'asc');
$data['successGalleries'] = getGalleriesByCategory(limit: 3, order: 'asc', category: 'voice-of-success');
$data['destinations'] = getDestinations(limit: null, order: 'asc');
$data['services'] = getServices(limit: null, order: 'asc');
$data['classes'] = getClasses(limit: null, order: 'asc');
$data['institutions'] = getInstitutions(limit: null, order: 'asc');
$data['faqs'] = getFAQs(limit: null, order: 'desc');
$data['testimonials'] = getTestimonials(limit: null, order: 'desc');
$data['blogs'] = getBlogs(limit: 4, order: 'desc');
$data['partners'] = getPartners(limit: 4, order: 'desc');
$data['gallaries'] = getGalleries(limit: 6, order: 'asc');
$data['achievementGalleries'] = getGalleriesByCategory(limit: null, order: 'asc', category: 'achievement');
$data['visaGalleries'] = getGalleriesByCategory(limit: null, order: 'asc', category: 'visa-success');
$page = $data['page'] = getPageWithChildrenBySlug(parent: null, slug: '/', limit: null, order: 'asc');
if (!$page) {
return view("client.$this->path.errors.404");
}
$path = "client.$this->path.pages.$page->template";
if (!View::exists($path)) {
return view("client.$this->path.errors.404");
}
return view($path, $data);
}
public function blogSingle($alias)
{
$blog = $data["page"] = Blog::where('status', 1)
->where('slug', $alias)->first();
$data['blogs'] = getBlogs(limit: null, order: 'desc');
if (!$blog) {
return view("client.$this->path.errors.404");
}
$data['categories'] = getBlogCategories(limit: null, order: 'desc');
$data['recentBlogs'] = Blog::where('status', 1)
->where('id', '!=', $blog->id)
->inRandomOrder()
->orderBy('created_at', 'desc')
->take(5)->get();
$blog->increment('views');
return view("client.$this->path.pages.blog-single-template", $data);
}
public function serviceSingle($alias)
{
$service = $data["page"] = Service::where('status', 1)
->where('slug', $alias)
->with('children', function ($query) {
$query->where('status', 1)
->orderBy('order');
})
->first();
if (!$service) {
return view("client.$this->path.errors.404");
}
$data['recentServices'] = Service::where('status', 1)
->where('parent_id', null)
->orderBy('created_at', 'desc')
->inRandomOrder()
->take(5)->get();
$data['serviceFAQs'] = getFAQsByCategory(limit: null, order: 'desc', category: $service->slug);
return view("client.$this->path.pages.test-single-template", $data);
}
public function testSingle($alias)
{
$testPreparations = $data["page"] = Test::where('status', 1)
->where('slug', $alias)
->with('children', function ($query) {
$query->where('status', 1)
->orderBy('order');
})
->first();
if (!$testPreparations) {
return view("client.$this->path.errors.404");
}
return view("client.$this->path.pages.test-single-template", $data);
}
public function countrySingle($alias)
{
$country = $data["page"] = Country::where('status', 1)
->where('slug', $alias)
->with('institutions', function ($query) {
$query->where('status', 1);
})
->first();
if (!$country) {
return view("client.$this->path.errors.404");
}
$data['countryFAQs'] = getFAQsByCategory(limit: null, order: 'desc', category: $country->slug);
$data['countryInstitutions'] = $country->institutions;
$data['recentCountries'] = Country::where('status', 1)
->where('id', '!=', $country->id)
->inRandomOrder()
->orderBy('created_at', 'desc')
->take(5)->get();
return view("client.$this->path.pages.study-destination-template", $data);
}
public function loadPage(?string $parent = null, ?string $slug = null)
{
if ($slug === null) {
$slug = $parent;
$parent = null;
}
$page = getPageWithChildrenBySlug(parent: $parent, slug: $slug, limit: null, order: 'asc');
$teams = getTeams(limit: null, order: 'asc');
$blogs = getBlogs(limit: null, order: 'asc');
if (!$page) {
return view('client.raffles.errors.404');
}
$path = "client.$this->path.pages.$page->template";
if (!View::exists($path)) {
return view('client.raffles.errors.404');
}
return view($path, ['page' => $page, 'teams' => $teams, 'blogs' => $blogs]);
}
public function fallback()
{
return view("client.$this->path.errors.404");
}
public function coursefinder(Request $request)
{
$data['page'] = Page::where(['slug' => 'course-finder', 'status' => 1])->first();
$data['title'] = 'Program List';
$data['programs'] = $this->programService->findAll($request);
$data['countryOptions'] = Country::where('status', 1)->where('parent_id', null)->pluck('title', 'id');
$data['institutionOptions'] = Institution::query()
->when($request->filled('country_id'), function ($query) use ($request) {
$query->where('country_id', $request->country_id);
})
->pluck('title', 'id');
$data['programLevelOptions'] = ProgramLevel::where('status', 1)->pluck('title', 'id');
$data['intakeOptions'] = Program::INTAKE;
$data['coopOptions'] = Coop::where('status', 1)->pluck('title', 'id');
$data['testOptions'] = Test::where('status', 1)->where('parent_id', null)->pluck('title', 'id');
$data['statusOptions'] = config('constants.page_status_options');
return view("client.$this->path.pages.coursefinder-template", $data);
}
public function resources()
{
$data['countries'] = Country::where('status', 1)->where('parent_id', null)->get();
$data['tests'] = Test::where('status', 1)->where('parent_id', null)->get();
$data['interviews'] = Service::where('status', 1)->where('parent_id', null)->get();
return view("client.raffles.pages.resources-template", $data);
}
}

View File

@@ -0,0 +1,63 @@
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
use Spatie\Permission\Exceptions\UnauthorizedException;
use Spatie\Permission\Guard;
class PermissionMiddleware
{
public function handle($request, Closure $next, $guard = null)
{
$authGuard = Auth::guard($guard);
$user = $authGuard->user();
// For machine-to-machine Passport clients
if (!$user && $request->bearerToken() && config('permission.use_passport_client_credentials')) {
$user = Guard::getPassportClient($guard);
}
if (!$user) {
throw UnauthorizedException::notLoggedIn();
}
if (!method_exists($user, 'hasAnyPermission')) {
throw UnauthorizedException::missingTraitHasRoles($user);
}
if ($user->hasRole('admin')) {
return $next($request);
}
foreach ($user->roles as $role) {
if ($role->hasPermissionTo($request->route()->getName())) {
return $next($request);
}
}
throw UnauthorizedException::forPermissions($user->getAllPermissions()->toArray());
}
/**
* Specify the permission and guard for the middleware.
*
* @param array|string $permission
* @param string|null $guard
* @return string
*/
public static function using($permission, $guard = null)
{
$permissionString = is_string($permission) ? $permission : implode('|', $permission);
$args = is_null($guard) ? $permissionString : "$permissionString,$guard";
return static::class . ':' . $args;
}
}

View File

@@ -0,0 +1,85 @@
<?php
namespace App\Http\Requests\Auth;
use Illuminate\Auth\Events\Lockout;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
class LoginRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
*/
public function rules(): array
{
return [
'email' => ['required', 'string', 'email'],
'password' => ['required', 'string'],
];
}
/**
* Attempt to authenticate the request's credentials.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function authenticate(): void
{
$this->ensureIsNotRateLimited();
if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
RateLimiter::hit($this->throttleKey());
throw ValidationException::withMessages([
'email' => trans('auth.failed'),
]);
}
RateLimiter::clear($this->throttleKey());
}
/**
* Ensure the login request is not rate limited.
*
* @throws \Illuminate\Validation\ValidationException
*/
public function ensureIsNotRateLimited(): void
{
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
return;
}
event(new Lockout($this));
$seconds = RateLimiter::availableIn($this->throttleKey());
throw ValidationException::withMessages([
'email' => trans('auth.throttle', [
'seconds' => $seconds,
'minutes' => ceil($seconds / 60),
]),
]);
}
/**
* Get the rate limiting throttle key for the request.
*/
public function throttleKey(): string
{
return Str::transliterate(Str::lower($this->string('email')).'|'.$this->ip());
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests;
use App\Models\User;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class ProfileUpdateRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
*/
public function rules(): array
{
return [
'name' => ['required', 'string', 'max:255'],
'email' => [
'required',
'string',
'lowercase',
'email',
'max:255',
Rule::unique(User::class)->ignore($this->user()->id),
],
];
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace App\Interfaces;
use Illuminate\Http\Request;
interface ModelInterface
{
public function findAll($request, callable $query = null, bool $paginate = false, int $limit = 10);
public function findById($id, callable $query = null);
public function delete($id);
public function create(array $data);
public function update($id, array $newDetails);
public function pluck(callable $query = null);
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Livewire;
use Livewire\Attributes\Validate;
use Livewire\Component;
class ToggleSwitch extends Component
{
#[Validate('required', 'in:sidebar,cpm-sidebar')]
public $sidebar;
public function toggle($isChecked)
{
$this->sidebar = $isChecked ? config('app.sidebar.other') : config('app.sidebar.default');
auth()->user()->update(['active_sidebar' => $this->sidebar]);
flash()->success("Dashboard has been toggled!");
$this->redirectRoute('dashboard');
}
public function render()
{
return view('livewire.toggle-switch');
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\Models\Scopes;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Support\Facades\Auth;
class CreatedByScope implements Scope
{
/**
* Apply the scope to a given Eloquent query builder.
*/
public function apply(Builder $builder, Model $model): void
{
if (auth()->user()->hasRole('admin')) {
//
}
if (auth()->user()->hasRole('employee')) {
$user = Auth::user();
$builder->where($model->getTable() . '.employee_id', $user->employee_id);
}
}
}

76
app/Models/User.php Normal file
View File

@@ -0,0 +1,76 @@
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Modules\Employee\Models\Employee;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable, HasRoles;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
'can_login',
'active_sidebar',
'order'
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
public function canLogin(): bool
{
return $this->can_login;
}
public function getRoles()
{
return $this->roles->map(function ($role) {
return "<span class='badge bg-primary p-1'>{$role->name}</span>";
})->implode(' ');
}
public function employee()
{
return $this->belongsTo(Employee::class, "user_id");
}
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'can_login' => 'boolean',
];
}
public static function getFillableFields()
{
return (new static())->getFillable();
}
}

View File

@@ -0,0 +1,62 @@
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class SendNotification extends Notification
{
use Queueable;
private $data;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct($data)
{
$this->data = $data;
}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['database'];
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
'msg' => $this->data['msg'],
'link' => $this->data['link'],
];
// return [
// 'msg' => $this->data['msg'],
// 'title' => $this->data['title'],
// 'description' => $this->data['description'],
// ];
}
}

View File

@@ -0,0 +1,44 @@
<?php
namespace App\Providers;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\ServiceProvider;
use Nwidart\Modules\Facades\Module;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*/
public function register(): void
{
//
}
/**
* Bootstrap any application services.
*/
public function boot(): void
{
Module::macro('sidebarMenu', function ($activeSidebar) {
return view('components.dashboard.sidebar-menu', [
'menus' => config($activeSidebar),
]);
});
Module::macro('isModuleEnabled', function ($moduleName) {
if (Module::has($moduleName)) {
$module = Module::find($moduleName);
return $module->isStatus(1);
}
return false;
});
Paginator::useBootstrapFive();
}
}

29
app/Rules/Recaptcha.php Normal file
View File

@@ -0,0 +1,29 @@
<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Facades\Http;
class Recaptcha implements ValidationRule
{
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$gResponseToken = (string) $value;
$response = Http::asForm()->post(
'https://www.google.com/recaptcha/api/siteverify',
['secret' => setting('recaptcha_secret_key'), 'response' => $gResponseToken]
);
if (!json_decode($response->body(), true)['success']) {
$fail('Invalid recaptcha');
}
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Traits;
use Illuminate\Support\Facades\Auth;
trait CreatedUpdatedBy
{
public static function bootCreatedUpdatedBy()
{
// updating createdby and updatedby when model is created
static::creating(function ($model) {
if (!$model->isDirty('createdby')) {
$model->createdby = auth()->user()->id ?? 1;
}
if (!$model->isDirty('updatedby')) {
$model->updatedby = auth()->user()->id ?? 1;
}
});
// updating updatedby when model is updated
static::updating(function ($model) {
if (!$model->isDirty('updatedby')) {
$model->updatedby = auth()->user()->id ?? 1;
}
});
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace App\Traits;
use Illuminate\Database\Eloquent\Casts\Attribute;
trait StatusTrait
{
const STATUS = [
11 => 'Active',
10 => 'In-Active',
];
protected function statusName(): Attribute
{
return Attribute::make(
get: function (mixed $value, array $attributes) {
switch ($attributes['status']) {
case '10':
return '<span class="badge bg-danger">' . self::STATUS[$attributes['status']] . '</span>';
case '11':
return '<span class="badge bg-success">' . self::STATUS[$attributes['status']] . '</span>';
default:
# code...
break;
}
},
set: fn($value) => $value,
);
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\View\Components;
use Illuminate\View\Component;
use Illuminate\View\View;
class AppLayout extends Component
{
/**
* Get the view / contents that represents the component.
*/
public function render(): View
{
return view('layouts.app');
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\View\Components;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class FlashMessage extends Component
{
/**
* Create a new component instance.
*/
public function __construct()
{
//
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.flash-message');
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\View\Components;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class FlatpickrInput extends Component
{
/**
* Create a new component instance.
*/
public function __construct()
{
//
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.flatpickr-input');
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\View\Components;
use Illuminate\View\Component;
use Illuminate\View\View;
class GuestLayout extends Component
{
/**
* Get the view / contents that represents the component.
*/
public function render(): View
{
return view('layouts.guest');
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\View\Components;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class ImageInput extends Component
{
/**
* Create a new component instance.
*/
public function __construct()
{
//
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.image-input');
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\View\Components\dashboard;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class Preloader extends Component
{
/**
* Create a new component instance.
*/
public function __construct()
{
//
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.dashboard.preloader');
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\View\Components\dashboard;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class RemoveNotificationModal extends Component
{
/**
* Create a new component instance.
*/
public function __construct()
{
//
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.dashboard.remove-notification-modal');
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\View\Components\dashboard;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class SidebarMenu extends Component
{
/**
* Create a new component instance.
*/
public function __construct()
{
//
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View | Closure | string
{
return view('components.dashboard.sidebar-menu');
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace App\View\Components\dashboard;
use Closure;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class ThemeChanger extends Component
{
/**
* Create a new component instance.
*/
public function __construct()
{
//
}
/**
* Get the view / contents that represent the component.
*/
public function render(): View|Closure|string
{
return view('components.dashboard.theme-changer');
}
}