Ticket 928

- add related model in accounts.index and creadit_logs.index
- Filter only current credit_logs of the related account in credit_logs.index
This commit is contained in:
Jérémy Munsch 2022-06-15 17:54:03 +02:00
parent b3c87ac735
commit ba87af1327
No known key found for this signature in database
GPG key ID: 18361AF3BFEC0FEC
6 changed files with 40 additions and 21 deletions

View file

@ -34,22 +34,16 @@ class AccountController extends Controller
*
* @param Builder $query
* @return Builder
* @throws \ErrorException If account is missing in url.
*/
public function indexQuery(Builder $query): Builder
{
/** @var \App\Models\User */
$user = auth()->user();
if (!$user->isAdmin()) {
// Show only users brand(s) accounts.
$brands = $user->sites()->with('brand')->get()->pluck('brand')
->filter(function ($v) {
return !\is_null($v);
});
return $query->whereHas('brand', function ($q) use ($brands) {
$q->whereIn('id', $brands->pluck('id'));
});
/** @var \App\Models\Brand|null $brand */
if (!($brand = request()->brand)) {
throw new \ErrorException('Cannot get brand');
}
return $query;
return $query->where('brand_id', '=', $brand->id);
}
/**

View file

@ -30,11 +30,20 @@ class CreditLogController extends Controller
*
* @param Builder $query
* @return Builder
* @throws \ErrorException If account is missing in url.
*/
public function indexQuery(Builder $query): Builder
{
$query->orderBy('created_at', 'DESC');
return $query;
/** @var \App\Models\Credit\Account|null $account */
if (!($account = request()->account)) {
throw new \ErrorException('Cannot get account');
}
return $query->whereHas('account', function ($q) use ($account) {
$q->whereIn('id', $account->pluck('id'));
});
}
/**

View file

@ -15,7 +15,7 @@
"fideloper/proxy": "^4.4",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"kwaadpepper/crud-policies": "^0.4.3",
"kwaadpepper/crud-policies": "^0.4.5",
"kwaadpepper/enum": "^2.1",
"kwaadpepper/exception-handler": "^0.0.9",
"laravel-lang/lang": "~8.0",

14
composer.lock generated
View file

@ -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": "b47b6f2c87a223409cd7086412a4463b",
"content-hash": "7231078f8b07ef175c85390302bb7298",
"packages": [
{
"name": "asm89/stack-cors",
@ -1505,16 +1505,16 @@
},
{
"name": "kwaadpepper/crud-policies",
"version": "0.4.4",
"version": "0.4.5",
"source": {
"type": "git",
"url": "https://github.com/Kwaadpepper/crud-policies.git",
"reference": "9fb72a59a3d9699a79e0c8862fd95491bd2b768a"
"reference": "c25ff96be976796a5447bd75d6ef16a0d7226f47"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Kwaadpepper/crud-policies/zipball/9fb72a59a3d9699a79e0c8862fd95491bd2b768a",
"reference": "9fb72a59a3d9699a79e0c8862fd95491bd2b768a",
"url": "https://api.github.com/repos/Kwaadpepper/crud-policies/zipball/c25ff96be976796a5447bd75d6ef16a0d7226f47",
"reference": "c25ff96be976796a5447bd75d6ef16a0d7226f47",
"shasum": ""
},
"require": {
@ -1565,9 +1565,9 @@
],
"support": {
"issues": "https://github.com/Kwaadpepper/crud-policies/issues",
"source": "https://github.com/Kwaadpepper/crud-policies/tree/0.4.4"
"source": "https://github.com/Kwaadpepper/crud-policies/tree/0.4.5"
},
"time": "2022-06-10T08:04:44+00:00"
"time": "2022-06-15T15:42:22+00:00"
},
{
"name": "kwaadpepper/enum",

View file

@ -30,6 +30,14 @@
</form>
</div>
</div>
<div class="row">
<div class="col-1">
<span class="fw-bold h4">{{ __('Marque')}}</span>
</div>
<div class="col">
<b class="h4">{{ optional(request()->brand)->name }}</b>
</div>
</div>
<table class="table text-center">
<thead class="thead-dark">
@include('crud-policies::crud.modules.sorter')

View file

@ -30,6 +30,14 @@
</form>
</div>
</div>
<div class="row">
<div class="col-1">
<span class="fw-bold h4">{{ __('Compte')}}</span>
</div>
<div class="col">
<b class="h4">{{ optional(request()->account)->label }}</b>
</div>
</div>
<table class="table text-center">
<thead class="thead-dark">
@include('crud-policies::crud.modules.sorter')