orderBy('id', 'desc')->first()->id ?? null; if ($lastExportedId) { $codesAvailableToExport = $codesAvailableToExport ->where('id', '>', $lastExportedId); } $this->merge([ 'available_export' => $codesAvailableToExport->count() ]); // ? Is auth and super admin, also is json ? return auth()->check() and auth()->user()->role === 1 and $this->json(); } /** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return [ 'nb_code_fic' => 'required|integer|min:1', 'nb_code_tot' => 'required|integer|min:1', 'nb_code_ligne' => 'required|integer|min:1', 'available_export' => 'required|integer|gte:nb_code_tot' ]; } /** * Get custom attributes for validator errors. * * @return array */ public function attributes(): array { return [ 'nb_code_fic' => 'Nombre total de codes à exporter', 'nb_code_tot' => 'Nombre de codes par fichier', 'nb_code_ligne' => 'Nombre de codes par ligne', 'available_export' => 'Nombre de codes restant à exporté(s)' ]; } }