firstcommit
This commit is contained in:
0
Modules/ContactUs/app/Http/Controllers/.gitkeep
Normal file
0
Modules/ContactUs/app/Http/Controllers/.gitkeep
Normal file
130
Modules/ContactUs/app/Http/Controllers/ContactUsController.php
Normal file
130
Modules/ContactUs/app/Http/Controllers/ContactUsController.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ContactUs\app\Http\Controllers;
|
||||
|
||||
use App\Mail\ReplyToMail;
|
||||
use App\Jobs\ReplyToMailJob;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\LogoService;
|
||||
use Illuminate\Http\Response;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Modules\ContactUs\app\Models\ContactUs;
|
||||
use Modules\ContactUs\app\Repositories\ContactUsRepository;
|
||||
use Modules\ContactUs\app\Http\Requests\CreateContactUsRequest;
|
||||
|
||||
class ContactUsController extends Controller
|
||||
{
|
||||
protected $contactUsRepository;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->contactUsRepository = new ContactUsRepository;
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$perPage = $request->has('per-page') ? $request->input('per-page') : null;
|
||||
$filter = $request->has('filter') ? $request->input('filter') : [];
|
||||
$data['contactUsList'] = $this->contactUsRepository->allContactList($perPage, $filter);
|
||||
|
||||
$data['contactUsCount'] = $data['contactUsList']->count();
|
||||
// dd(($data['contactUsCount']));
|
||||
|
||||
return view('contactus::index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
|
||||
public function replyToMail(LogoService $logoService, Request $request, $uuid)
|
||||
{
|
||||
$citizenEmail = ContactUs::where('uuid', $uuid)->first();
|
||||
if (!$citizenEmail) {
|
||||
return null;
|
||||
}
|
||||
dispatch(new ReplyToMailJob(
|
||||
$citizenEmail,
|
||||
$request->content,
|
||||
$logoService->getSiteLogo()
|
||||
));
|
||||
return redirect()->route('cms.contactUs.index');
|
||||
}
|
||||
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('contactus::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(CreateContactUsRequest $request): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$validated = $request->validated();
|
||||
$this->contactUsRepository->storeContactUsList($validated);
|
||||
|
||||
toastr()->success('Contact detail created successfully.');
|
||||
|
||||
return redirect()->route('cms.contactus.index');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($uuid)
|
||||
{
|
||||
$data['contactUs'] = $this->contactUsRepository->findContactUsListById($uuid);
|
||||
|
||||
return view('contactus::show', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('contactus::edit');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($uuid)
|
||||
{
|
||||
try {
|
||||
$contact_us = $this->contactUsRepository->deleteContactUsList($uuid);
|
||||
|
||||
if (!$contact_us) {
|
||||
toastr()->error('Contact detail not found.');
|
||||
return back();
|
||||
}
|
||||
|
||||
toastr()->success('Contact detail deleted successfully.');
|
||||
|
||||
return redirect()->route('cms.contactus.index');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
}
|
0
Modules/ContactUs/app/Http/Middleware/.gitkeep
Normal file
0
Modules/ContactUs/app/Http/Middleware/.gitkeep
Normal file
0
Modules/ContactUs/app/Http/Requests/.gitkeep
Normal file
0
Modules/ContactUs/app/Http/Requests/.gitkeep
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\ContactUs\app\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreateContactUsRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'full_name' => 'required|string|max:200|regex:/^[a-zA-Z. ]+$/',
|
||||
'address' => 'sometimes|nullable|string|max:200',
|
||||
'email' => 'sometimes|nullable|email',
|
||||
'subject' => 'sometimes|nullable|string|max:1000',
|
||||
'message' => 'required|string|max:1000',
|
||||
'phone' => 'sometimes|nullable|numeric|digits:10',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'full_name.required' => 'The full name field is required.',
|
||||
'full_name.string' => 'The full name must be a string.',
|
||||
'full_name.max' => 'The full name may not be greater than 200 characters.',
|
||||
'full_name.regex' => 'The full name may only contain letters, dots, and spaces.',
|
||||
|
||||
'address.string' => 'The address must be a string.',
|
||||
'address.max' => 'The address may not be greater than 200 characters.',
|
||||
|
||||
'email.email' => 'Invalid email format.',
|
||||
|
||||
'subject.string' => 'The subject must be a string.',
|
||||
'subject.max' => 'The subject may not be greater than 1000 characters.',
|
||||
|
||||
'message.required' => 'The message field is required.',
|
||||
'message.string' => 'The message must be a string.',
|
||||
'message.max' => 'The message may not be greater than 1000 characters.',
|
||||
|
||||
'phone.numeric' => 'The phone must be a number.',
|
||||
'phone.digits' => 'The phone must be exactly 10 digits long.'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user