<?php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; class ServiceChangeRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize() { return $this->route('o')->serviceUserAuthorised(Auth::user()); } /** * Get the validation rules that apply to the request. * * @return array<string, mixed> * @todo This is specific to broadband - this needs to be more generic. */ public function rules(Request $request) { if (! $request->isMethod('post')) return []; return [ 'broadband.product_id' => 'required|exists:products,id', 'broadband.change_fee' => 'nullable|numeric', 'broadband.price' => 'nullable|numeric', 'broadband.start_at' => 'required|date', // @todo Check that it is not more than 1 billing cycle ago, and not future. ]; } }