ldc-crm/app/Http/Controllers/SingleOptinsController.php

38 lines
960 B
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
use App\Http\Resources\StatusResource;
use App\Models\Brand;
use App\Models\SingleOptin;
class SingleOptinsController extends Controller
{
public function index()
{
$brands = Brand::select('id', 'name')->get();
return view('single-optins.index', compact('brands'));
}
public function filter($texte, $brandId = null)
{
if ($brandId !== null) {
$customers = SingleOptin::where([['email', 'like', '%' . $texte . '%'], ['brand_id', $brandId]])->get();
} else {
$customers = SingleOptin::where('email', 'like', '%' . $texte . '%')->get();
}
return response()->json($customers);
}
public function delete($id)
{
// TODO : Gestion avec les stats
$optin = SingleOptin::find($id);
if ($optin) {
$optin->delete();
}
return new StatusResource(['status' => "OK"]);
}
}