bump kwaadpepper/crud-policies
Customer search
This commit is contained in:
parent
193a93715e
commit
78bbd8fafb
5 changed files with 67 additions and 45 deletions
|
|
@ -9,23 +9,64 @@ use App\Models\Customer;
|
|||
use App\Models\CustomerInfo;
|
||||
use App\Models\CustomerLogin;
|
||||
use App\Models\SingleOptin;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Str;
|
||||
use League\Csv\Writer;
|
||||
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||
|
||||
class CustomerController extends Controller
|
||||
{
|
||||
public function index()
|
||||
public function index(Request $request)
|
||||
{
|
||||
$brands = Brand::select('id', 'name')->get();
|
||||
$query = CustomerInfo::with(['customer']);
|
||||
if (request()->brand) {
|
||||
$query = $query->where('brand_id', request()->brand);
|
||||
}
|
||||
$customers = $query->paginate();
|
||||
$modelTable = (new Customer())->getTable();
|
||||
$modelClass = Customer::class;
|
||||
$brands = Brand::select('id', 'name')->get();
|
||||
$columns = ['lastname', 'firstname', 'opt_in'];
|
||||
|
||||
/** @var \Illuminate\Database\Eloquent\Builder */
|
||||
$query = CustomerInfo::with(['customer']);
|
||||
if (request()->brand) {
|
||||
$query = $query->where('brand_id', $request->brand);
|
||||
}
|
||||
|
||||
// Search on crud Label column
|
||||
if ($request->search) {
|
||||
foreach ($columns as $column) {
|
||||
$query = $query->orWhere($column, 'LIKE', "%$request->search%");
|
||||
}
|
||||
$query = $query->orWhereHas('customer', function ($q) use ($request) {
|
||||
$q->where('email', 'LIKE', "%$request->search%");
|
||||
});
|
||||
}
|
||||
|
||||
// Sort columns
|
||||
if ($request->sort_col) {
|
||||
Session::put("crud.$modelTable.sort_col", $request->sort_col);
|
||||
}
|
||||
if ($request->sort_way) {
|
||||
Session::put("crud.$modelTable.sort_way", $request->sort_way);
|
||||
}
|
||||
|
||||
if ($request->rst) {
|
||||
Session::remove("crud.$modelTable.sort_way");
|
||||
Session::remove("crud.$modelTable.sort_col");
|
||||
}
|
||||
if (
|
||||
Session::has("crud.$modelTable.sort_col") and
|
||||
Session::has("crud.$modelTable.sort_way") and
|
||||
Schema::hasColumn($modelTable, Session::get("crud.$modelTable.sort_col"))
|
||||
) {
|
||||
$query = $query->orderBy(
|
||||
Session::get("crud.$modelTable.sort_col"),
|
||||
Session::get("crud.$modelTable.sort_way")
|
||||
);
|
||||
}
|
||||
|
||||
/** @var \Illuminate\Pagination\AbstractPaginator */
|
||||
$customers = $query->paginate(config('crud.paginate', 50));
|
||||
|
||||
// use a crud controller (any) to gather crudModels
|
||||
$modelsClasses = (new BrandController())->getCrudModels();
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@
|
|||
"fideloper/proxy": "^4.4",
|
||||
"fruitcake/laravel-cors": "^2.0",
|
||||
"guzzlehttp/guzzle": "^7.0.1",
|
||||
"kwaadpepper/crud-policies": "^0.1.15",
|
||||
"kwaadpepper/crud-policies": "^0.1.17",
|
||||
"kwaadpepper/enum": "^2.0",
|
||||
"laravel-lang/lang": "~7.0",
|
||||
"laravel/framework": "^8.39",
|
||||
|
|
|
|||
15
composer.lock
generated
15
composer.lock
generated
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "ad679e344512ce53865817160816c3fa",
|
||||
"content-hash": "52ddf0e771e6661178474f2a87aeaf7e",
|
||||
"packages": [
|
||||
{
|
||||
"name": "arondeparon/laravel-request-sanitizer",
|
||||
|
|
@ -1730,16 +1730,16 @@
|
|||
},
|
||||
{
|
||||
"name": "kwaadpepper/crud-policies",
|
||||
"version": "0.1.15",
|
||||
"version": "0.1.17",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/Kwaadpepper/crud-policies.git",
|
||||
"reference": "cf471dc2dad7851474ee005fbc8dfdfe05096b84"
|
||||
"reference": "007552cbc9f34790acadf1fde1da2eed347be1b9"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/Kwaadpepper/crud-policies/zipball/cf471dc2dad7851474ee005fbc8dfdfe05096b84",
|
||||
"reference": "cf471dc2dad7851474ee005fbc8dfdfe05096b84",
|
||||
"url": "https://api.github.com/repos/Kwaadpepper/crud-policies/zipball/007552cbc9f34790acadf1fde1da2eed347be1b9",
|
||||
"reference": "007552cbc9f34790acadf1fde1da2eed347be1b9",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
|
@ -1751,6 +1751,7 @@
|
|||
"require-dev": {
|
||||
"orchestra/testbench": "^6.13",
|
||||
"phpunit/phpunit": "~9.0",
|
||||
"slevomat/coding-standard": "^7.0",
|
||||
"squizlabs/php_codesniffer": "^3.5"
|
||||
},
|
||||
"type": "library",
|
||||
|
|
@ -1787,9 +1788,9 @@
|
|||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/Kwaadpepper/crud-policies/issues",
|
||||
"source": "https://github.com/Kwaadpepper/crud-policies/tree/0.1.15"
|
||||
"source": "https://github.com/Kwaadpepper/crud-policies/tree/0.1.17"
|
||||
},
|
||||
"time": "2021-08-27T10:42:55+00:00"
|
||||
"time": "2021-09-09T12:42:59+00:00"
|
||||
},
|
||||
{
|
||||
"name": "kwaadpepper/enum",
|
||||
|
|
|
|||
|
|
@ -1,62 +1,41 @@
|
|||
<th scope="col">
|
||||
@php $colname = 'email' @endphp
|
||||
{{ __('Email')}}
|
||||
@if(!session("crud.$modelTable.sort_way") or session("crud.$modelTable.sort_col") !== $colname or (session("crud.$modelTable.sort_way") === 'desc' and session("crud.$modelTable.sort_col") === $colname))
|
||||
<a class="col_sort text-secondary lead asc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'asc']) }}"> ↓ </a>
|
||||
@endif
|
||||
@if(!session("crud.$modelTable.sort_way") or session("crud.$modelTable.sort_col") !== $colname or (session("crud.$modelTable.sort_way") === 'asc' and session("crud.$modelTable.sort_col") === $colname))
|
||||
<a class="col_sort text-secondary lead desc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'desc']) }}"> ↑ </a>
|
||||
@endif
|
||||
</th>
|
||||
<th scope="col">
|
||||
@php $colname = 'lastname' @endphp
|
||||
{{ __('Nom')}}
|
||||
@if(!session("crud.$modelTable.sort_way") or session("crud.$modelTable.sort_col") !== $colname or (session("crud.$modelTable.sort_way") === 'desc' and session("crud.$modelTable.sort_col") === $colname))
|
||||
<a class="col_sort text-secondary lead asc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'asc']) }}"> ↓ </a>
|
||||
<a class="col_sort text-secondary lead asc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'asc', 'rst' => null]) }}"> ↓ </a>
|
||||
@endif
|
||||
@if(!session("crud.$modelTable.sort_way") or session("crud.$modelTable.sort_col") !== $colname or (session("crud.$modelTable.sort_way") === 'asc' and session("crud.$modelTable.sort_col") === $colname))
|
||||
<a class="col_sort text-secondary lead desc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'desc']) }}"> ↑ </a>
|
||||
<a class="col_sort text-secondary lead desc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'desc', 'rst' => null]) }}"> ↑ </a>
|
||||
@endif
|
||||
</th>
|
||||
<th scope="col">
|
||||
@php $colname = 'firstname' @endphp
|
||||
{{ __('Prénom')}}
|
||||
@if(!session("crud.$modelTable.sort_way") or session("crud.$modelTable.sort_col") !== $colname or (session("crud.$modelTable.sort_way") === 'desc' and session("crud.$modelTable.sort_col") === $colname))
|
||||
<a class="col_sort text-secondary lead asc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'asc']) }}"> ↓ </a>
|
||||
<a class="col_sort text-secondary lead asc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'asc', 'rst' => null]) }}"> ↓ </a>
|
||||
@endif
|
||||
@if(!session("crud.$modelTable.sort_way") or session("crud.$modelTable.sort_col") !== $colname or (session("crud.$modelTable.sort_way") === 'asc' and session("crud.$modelTable.sort_col") === $colname))
|
||||
<a class="col_sort text-secondary lead desc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'desc']) }}"> ↑ </a>
|
||||
<a class="col_sort text-secondary lead desc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'desc', 'rst' => null]) }}"> ↑ </a>
|
||||
@endif
|
||||
</th>
|
||||
<th scope="col">
|
||||
@php $colname = 'optin' @endphp
|
||||
@php $colname = 'opt_in' @endphp
|
||||
{{ __('Opt-In')}}
|
||||
@if(!session("crud.$modelTable.sort_way") or session("crud.$modelTable.sort_col") !== $colname or (session("crud.$modelTable.sort_way") === 'desc' and session("crud.$modelTable.sort_col") === $colname))
|
||||
<a class="col_sort text-secondary lead asc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'asc']) }}"> ↓ </a>
|
||||
<a class="col_sort text-secondary lead asc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'asc', 'rst' => null]) }}"> ↓ </a>
|
||||
@endif
|
||||
@if(!session("crud.$modelTable.sort_way") or session("crud.$modelTable.sort_col") !== $colname or (session("crud.$modelTable.sort_way") === 'asc' and session("crud.$modelTable.sort_col") === $colname))
|
||||
<a class="col_sort text-secondary lead desc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'desc']) }}"> ↑ </a>
|
||||
<a class="col_sort text-secondary lead desc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'desc', 'rst' => null]) }}"> ↑ </a>
|
||||
@endif
|
||||
</th>
|
||||
<th scope="col">
|
||||
@php $colname = 'brand_id' @endphp
|
||||
{{ __('Marque')}}
|
||||
@if(!session("crud.$modelTable.sort_way") or session("crud.$modelTable.sort_col") !== $colname or (session("crud.$modelTable.sort_way") === 'desc' and session("crud.$modelTable.sort_col") === $colname))
|
||||
<a class="col_sort text-secondary lead asc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'asc']) }}"> ↓ </a>
|
||||
@endif
|
||||
@if(!session("crud.$modelTable.sort_way") or session("crud.$modelTable.sort_col") !== $colname or (session("crud.$modelTable.sort_way") === 'asc' and session("crud.$modelTable.sort_col") === $colname))
|
||||
<a class="col_sort text-secondary lead desc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'desc']) }}"> ↑ </a>
|
||||
@endif
|
||||
</th>
|
||||
<th scope="col">
|
||||
@php $colname = 'status' @endphp
|
||||
{{ __('Activé ?')}}
|
||||
@if(!session("crud.$modelTable.sort_way") or session("crud.$modelTable.sort_col") !== $colname or (session("crud.$modelTable.sort_way") === 'desc' and session("crud.$modelTable.sort_col") === $colname))
|
||||
<a class="col_sort text-secondary lead asc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'asc']) }}"> ↓ </a>
|
||||
@endif
|
||||
@if(!session("crud.$modelTable.sort_way") or session("crud.$modelTable.sort_col") !== $colname or (session("crud.$modelTable.sort_way") === 'asc' and session("crud.$modelTable.sort_col") === $colname))
|
||||
<a class="col_sort text-secondary lead desc" href="{{ request()->fullUrlWithQuery(['sort_col' => $colname, 'sort_way' => 'desc']) }}"> ↑ </a>
|
||||
@endif
|
||||
</th>
|
||||
<th scope="col">
|
||||
{{ __('Voir')}}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@
|
|||
</form>
|
||||
</div>
|
||||
</div>
|
||||
{{ $customers->appends(Request::except('rst'))->links() }}
|
||||
<table class="table text-center">
|
||||
<thead class="thead-dark">
|
||||
<tr>
|
||||
|
|
@ -66,7 +67,7 @@
|
|||
{{ $customerInfo->lastname }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $customerInfo->optin ? 'Oui' :'Non' }}
|
||||
{{ $customerInfo->opt_in ? 'Oui' :'Non' }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $customerInfo->brand->name }}
|
||||
|
|
@ -97,7 +98,7 @@
|
|||
@endif
|
||||
</tbody>
|
||||
</table>
|
||||
{{ $customers->links() }}
|
||||
{{ $customers->appends(Request::except('rst'))->links() }}
|
||||
</div>
|
||||
</div>
|
||||
@include('crud-policies::crud.modules.scriptConstants')
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue