Merge branch 'develop' into trunk
This commit is contained in:
commit
e1d72fdc59
5 changed files with 87 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\CustomerDeleteRequest;
|
||||
use App\Models\Brand;
|
||||
use App\Models\Customer;
|
||||
use App\Models\CustomerInfos;
|
||||
|
|
@ -44,4 +45,19 @@ class CustomerController extends Controller
|
|||
|
||||
return response()->json($customers);
|
||||
}
|
||||
|
||||
public function delete(CustomerDeleteRequest $request, Customer $customer, Brand $brand)
|
||||
{
|
||||
$nbBrand = $customer->infos()->count();
|
||||
|
||||
$customer->infos()->where('brand_id', $brand->id)->delete();
|
||||
$customer->logins()->where('brand_id', $brand->id)->delete();
|
||||
$customer->optInHistory()->where('brand_id', $brand->id)->delete();
|
||||
|
||||
if ($nbBrand === 1) {
|
||||
$customer->delete();
|
||||
}
|
||||
|
||||
return redirect()->route('customers')->with('success', "Compte supprimé.");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
38
app/Http/Requests/CustomerDeleteRequest.php
Normal file
38
app/Http/Requests/CustomerDeleteRequest.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class CustomerDeleteRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return Auth::check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'customer' => 'exists:customers,id|required',
|
||||
'brand' => 'exists:brands,id|required'
|
||||
];
|
||||
}
|
||||
|
||||
protected function prepareForValidation()
|
||||
{
|
||||
$this->merge(['customer' => $this->route('customer')->id, 'brand' => $this->route('brand')->id]);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,23 @@
|
|||
@extends('layout.app')
|
||||
|
||||
@section('content')
|
||||
@if (session()->has('success'))
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3">
|
||||
<div class="alert alert-success">
|
||||
<p>{{ session()->get('success') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@if ($errors->any())
|
||||
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3">
|
||||
<div class="alert alert-danger">
|
||||
<ul>
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
<search-user dbbrands='@json($brands)'></search-user>
|
||||
@endsection
|
||||
|
|
|
|||
|
|
@ -5,6 +5,15 @@
|
|||
<h1 class="h2">Informations du client {{ $customerInfos->firstname }} {{ $customerInfos->lastname }} - Marque {{ $customerInfos->brand->name }}</h1>
|
||||
<a href="{{ route('customers') }}" class="btn btn-sm btn-primary float-right">Retour</a>
|
||||
</div>
|
||||
@if ($errors->any())
|
||||
<div class="alert alert-danger">
|
||||
<ul>
|
||||
@foreach ($errors->all() as $error)
|
||||
<li>{{ $error }}</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
@endif
|
||||
<table class="table table-sm table-bordered table-striped">
|
||||
<tbody>
|
||||
<tr>
|
||||
|
|
@ -81,4 +90,9 @@
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<form action="{{ route('customers.delete', ['customer' => $customerInfos->customer_id, 'brand' => $customerInfos->brand->id]) }}" method="POST" onsubmit="return confirm('{{ __('Êtes-vous sûr de vouloir supprimer cet utilisateur ?') }}');">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<input type="submit" value="{{ __('Supprimer') }}" class="btn btn-sm btn-danger">
|
||||
</form>
|
||||
@endsection
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ Route::middleware(['auth'])->group(function () {
|
|||
Route::get('/customers', [CustomerController::class, 'index'])->name('customers');
|
||||
Route::get('/customers/filter/{texte}/{brandId?}', [CustomerController::class, 'filter'])->name('filter-customer');
|
||||
Route::get('/customer/{id}/{brandId}', [CustomerController::class, 'show'])->name('show-customer');
|
||||
Route::delete('/customer/{customer}/{brand}', [CustomerController::class, 'delete'])->name('customers.delete');
|
||||
// Single optins
|
||||
Route::get('/single-optins', [SingleOptinsController::class, 'index'])->name('single-optins');
|
||||
Route::get('/single-optins/filter/{texte}/{brandId?}', [SingleOptinsController::class, 'filter'])->name('filter-single-optins');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue