brand; $credit_accountModel = $request->account; /** @var \Illuminate\Database\Eloquent\Builder $credit_logModels */ $credit_logModels = CreditLog::query()->where('credit_account_id', $credit_accountModel->id); /** @var string $search Search field */ $search = $request->search; if ($search) { $this->searchQuery( $credit_logModels, $search, null, 'amount', ); } $searchFields = trans('Montant'); /** Sort columns with a query */ $this->sortQuery($credit_logModels); /** Custom pagination */ $credit_logModels = $this->customPaginate($credit_logModels, $request->pagination); return view('bo.pages.credit_logs.index', compact( 'credit_logModels', 'credit_accountModel', 'brandModel', 'search', 'searchFields' )); } /** * Show the form for creating a new resource. * * @param \App\Models\Brand $brand * @param \App\Models\Account $account * @return \Illuminate\Contracts\View\View */ public function create(Brand $brand, Account $account): \Illuminate\Contracts\View\View { return view('bo.pages.credit_logs.create', [ 'brandModel' => $brand, 'credit_accountModel' => $account ]); } /** * Store a newly created resource in storage. * * @param \App\Models\Brand $brand * @param \App\Models\Account $account * @param \App\Http\Requests\Bo\CreditLogs\StoreCreditLogRequest $request * @return \Illuminate\Http\RedirectResponse */ public function store( Brand $brand, Account $account, StoreCreditLogRequest $request ): \Illuminate\Http\RedirectResponse { return DB::transaction(function () use ($brand, $account, $request) { $credit_logModel = new CreditLog(); $credit_logModel->credit_account_id = $request->account->id; $credit_logModel->type = BalanceOperationEnum::credit; $credit_logModel->fill($request->validated()); if ($credit_logModel->saveOrFail()) { return redirect() ->route('bo.brands.credit_accounts.index', ['brand' => $brand, 'account' => $account]) ->with('success', trans( ':model a été crédité', ['model' => Str::singular(trans('models.classes.accounts'))] )); } return redirect() ->back() ->with('error', trans( ':model ne peut être crédité', ['model' => Str::singular(trans('models.classes.accounts'))] )); }); } }