Validate input of update function in EarningController
MODIFY
app/Http/Controllers/EarningController.php
app/Http/Controllers/EarningController.php
@@ -9,6 +9,14 @@ use App\Earning;
use Auth;
class EarningController extends Controller {
+ protected function validationRules() {
+ return [
+ 'date' => 'required|date|date_format:Y-m-d',
+ 'description' => 'required|max:255',
+ 'amount' => 'required|regex:/^\d*(\.\d{2})?$/'
+ ];
+ }
+
public function index() {
$user = Auth::user();
@@ -26,11 +34,7 @@ class EarningController extends Controller {
}
public function store(Request $request) {
- $request->validate([
- 'date' => 'required|date|date_format:Y-m-d',
- 'description' => 'required|max:255',
- 'amount' => 'required|regex:/^\d*(\.\d{2})?$/'
- ]);
+ $request->validate($this->validationRules());
$earning = new Earning;
@@ -53,7 +57,7 @@ class EarningController extends Controller {
public function update(Request $request, Earning $earning) {
$this->authorize('update', $earning);
- // TODO VALIDATE
+ $request->validate($this->validationRules());
$earning->fill([
'happened_on' => $request->input('date'),

Validate input of update function in EarningController