2021-09-08 16:43:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
2023-10-06 15:00:42 +02:00
|
|
|
namespace App\Http\Controllers\Bo;
|
2021-09-08 16:43:44 +02:00
|
|
|
|
2023-10-06 15:00:42 +02:00
|
|
|
use App\Http\Controllers\Controller;
|
2025-07-23 17:14:51 +02:00
|
|
|
use App\Models\Answer;
|
|
|
|
|
use App\Models\Question;
|
2021-09-08 16:43:44 +02:00
|
|
|
use App\Models\SingleOptin;
|
2023-06-15 14:40:51 +02:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Str;
|
2021-09-08 16:43:44 +02:00
|
|
|
|
|
|
|
|
class SingleOptinController extends Controller
|
|
|
|
|
{
|
2025-07-28 09:46:22 +02:00
|
|
|
/**
|
|
|
|
|
* Create the controller instance.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->authorizeResource(SingleOptin::class);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
2023-06-15 15:32:20 +02:00
|
|
|
* Display a listing of the resource.
|
2021-12-19 15:57:24 +01:00
|
|
|
*
|
2023-06-23 17:18:59 +02:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2023-09-06 17:24:53 +02:00
|
|
|
* @return \Illuminate\Contracts\View\View
|
2021-12-19 15:57:24 +01:00
|
|
|
*/
|
2023-09-06 17:24:53 +02:00
|
|
|
public function index(Request $request): \Illuminate\Contracts\View\View
|
2021-12-19 15:57:24 +01:00
|
|
|
{
|
2023-06-15 14:40:51 +02:00
|
|
|
/** @var \Illuminate\Database\Eloquent\Builder $query */
|
2025-07-23 17:14:51 +02:00
|
|
|
$query = SingleOptin::query()
|
|
|
|
|
->when(
|
|
|
|
|
$request->filled('brand'),
|
|
|
|
|
fn($q) => $q->whereHas('brand', fn($q) => $q->where('id', $request->brand))
|
|
|
|
|
)
|
|
|
|
|
->when(
|
|
|
|
|
$request->filled('answer'),
|
|
|
|
|
fn($q) => $q->whereHas('answers', fn($q) => $q->where('id', $request->answer))
|
|
|
|
|
);
|
2023-06-15 14:40:51 +02:00
|
|
|
|
2025-07-23 17:14:51 +02:00
|
|
|
if ($request->filled('search')) {
|
2023-06-15 14:40:51 +02:00
|
|
|
$this->searchQuery(
|
|
|
|
|
$query,
|
|
|
|
|
$request->search,
|
|
|
|
|
null,
|
|
|
|
|
'email',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->sortQuery($query);
|
2025-07-23 17:14:51 +02:00
|
|
|
$query->with('brand');
|
2023-06-15 14:40:51 +02:00
|
|
|
|
2023-10-06 15:00:42 +02:00
|
|
|
$singleoptinModels = $this->paginate($query);
|
2025-07-23 17:14:51 +02:00
|
|
|
$searchFields = trans('E-mail');
|
|
|
|
|
|
|
|
|
|
if ($request->filled('brand')) {
|
|
|
|
|
$questionModels = Question::where('brand_id', $request->brand)->get();
|
2023-06-15 14:40:51 +02:00
|
|
|
|
2025-07-23 17:14:51 +02:00
|
|
|
if ($request->filled('question')) {
|
|
|
|
|
$answerModels = Answer::where('question_id', $request->question)->get();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return view('bo.pages.singleoptins.index', [
|
|
|
|
|
'singleoptinModels' => $singleoptinModels,
|
|
|
|
|
'searchFields' => $searchFields,
|
|
|
|
|
'questionModels' => $questionModels ?? null,
|
|
|
|
|
'answerModels' => $answerModels ?? null,
|
|
|
|
|
]);
|
2021-12-19 15:57:24 +01:00
|
|
|
}
|
|
|
|
|
|
2025-07-23 17:14:51 +02:00
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
2023-06-15 14:40:51 +02:00
|
|
|
* Remove the specified resource from storage.
|
2021-12-19 15:57:24 +01:00
|
|
|
*
|
2023-06-15 14:40:51 +02:00
|
|
|
* @param \App\Models\SingleOptin $singleoptin
|
|
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2021-12-19 15:57:24 +01:00
|
|
|
*/
|
2023-06-15 14:40:51 +02:00
|
|
|
public function destroy(SingleOptin $singleoptin): \Illuminate\Http\RedirectResponse
|
2021-09-08 16:43:44 +02:00
|
|
|
{
|
2023-06-15 14:40:51 +02:00
|
|
|
if ($singleoptin->deleteOrFail()) {
|
2023-10-06 15:00:42 +02:00
|
|
|
return redirect()->route('bo.single_optins.index')
|
2023-06-22 17:25:52 +02:00
|
|
|
->with('success', trans(
|
|
|
|
|
':model a été supprimé.',
|
|
|
|
|
['model' => Str::singular(trans('models.classes.singleoptins'))]
|
|
|
|
|
));
|
2021-09-08 16:43:44 +02:00
|
|
|
}
|
2023-06-15 14:40:51 +02:00
|
|
|
return redirect()->back()
|
|
|
|
|
->with('error', trans(
|
|
|
|
|
':model n\'a pas pu être supprimé.',
|
|
|
|
|
['model' => Str::singular(trans('models.classes.singleoptins'))]
|
|
|
|
|
));
|
2021-09-08 16:43:44 +02:00
|
|
|
}
|
|
|
|
|
}
|