firstcommit
This commit is contained in:
0
Modules/Subscription/app/Http/Controllers/.gitkeep
Normal file
0
Modules/Subscription/app/Http/Controllers/.gitkeep
Normal file
@@ -0,0 +1,119 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Subscription\app\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\LogoService;
|
||||
use Illuminate\Http\Response;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Jobs\SendSubscriptionMailJob;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Modules\Setting\app\Models\Setting;
|
||||
use Modules\Subscription\app\Repositories\SubscriptionRepository;
|
||||
|
||||
class SubscriptionController extends Controller
|
||||
{
|
||||
|
||||
protected $subscriptionRepository;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->subscriptionRepository = new SubscriptionRepository();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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') : [];
|
||||
$subscription = $this->subscriptionRepository->allSubscriptionsEmail($perPage, $filter);
|
||||
|
||||
return view('subscription::index', compact('subscription'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('subscription::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(LogoService $logoService, Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'email' => 'required|email|unique:subscriptions,email',
|
||||
]);
|
||||
|
||||
try {
|
||||
$subscription = $this->subscriptionRepository->storeSubscription($validated);
|
||||
|
||||
$thumbImage = asset('frontend/images/mail/thumb.png');
|
||||
|
||||
dispatch(new SendSubscriptionMailJob(
|
||||
citizenEmail: $subscription->email,
|
||||
siteLogo: $logoService->getSiteLogo(),
|
||||
thumbImage: $thumbImage ?? ''
|
||||
));
|
||||
toastr()->success('Thanks for subscribe');
|
||||
return redirect()->route('home');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back()->withInput();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('subscription::show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
return view('subscription::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 {
|
||||
$subscription = $this->subscriptionRepository->deleteSubscriptionEmail($uuid);
|
||||
|
||||
if (!$subscription) {
|
||||
toastr()->error('Subscription email not found.');
|
||||
return back();
|
||||
}
|
||||
|
||||
toastr()->success('Subscription email deleted successfully.');
|
||||
|
||||
return redirect()->route('cms.subscription.index');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
}
|
0
Modules/Subscription/app/Http/Middleware/.gitkeep
Normal file
0
Modules/Subscription/app/Http/Middleware/.gitkeep
Normal file
0
Modules/Subscription/app/Http/Requests/.gitkeep
Normal file
0
Modules/Subscription/app/Http/Requests/.gitkeep
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Subscription\app\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreateSubscriptionRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'email' => 'required|email',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user