From a3d432a6a0710261149fdaecdc2a5a62a82fe303 Mon Sep 17 00:00:00 2001 From: Mateja Date: Tue, 27 Oct 2020 23:17:19 +0100 Subject: Validator::make and html5 required --- app/Http/Controllers/PagesController.php | 55 +++++++++++++++----------------- database/factories/PostFactory.php | 2 +- resources/views/pages/index.blade.php | 2 +- resources/views/pages/login.blade.php | 4 +-- resources/views/pages/reserve.blade.php | 18 +++++------ 5 files changed, 39 insertions(+), 42 deletions(-) diff --git a/app/Http/Controllers/PagesController.php b/app/Http/Controllers/PagesController.php index 3955254..5041f05 100644 --- a/app/Http/Controllers/PagesController.php +++ b/app/Http/Controllers/PagesController.php @@ -7,6 +7,9 @@ use App\Models\Post; use function dd; use function redirect; +use Illuminate\Support\Facades\Validator; +use Illuminate\Support\Facades\Redirect; + class PagesController extends Controller { public function index(Request $request) @@ -19,8 +22,6 @@ class PagesController extends Controller return view('pages.sponsoring'); } - //-------------------------------------- - public function news(Request $request) { $news = Post::all(); @@ -51,8 +52,6 @@ class PagesController extends Controller public function reserveForm(Request $request) { - //dd($request->input('modes')); - $validatedData = $request->validate([ 'scall' => 'required|alphanum', 'sdate' => 'required|date', @@ -67,38 +66,36 @@ class PagesController extends Controller 'phone' => ['required', 'regex:/^[0-9 ]+$/'], ]); -/* - $table->id(); - $table->boolean('approved')->default(false); - $table->unsignedBigInteger('specialCall'); - $table->dateTime('fromTime'); - $table->dateTime('toTime'); - $table->string('frequencies', 255); - $table->string('modes', 255); - $table->string('operatorCall'); - $table->string('operatorName'); - $table->string('operatorEmail'); - $table->string('operatorPhone', 50); - $table->integer('qso')->default(0); - $table->timestamps(); - $table->foreign('specialCall')->references('id')->on('special_calls'); -*/ - return redirect('reserve')->with('status', 'Reservation submitted.'); } - /** - * undocumented function - * - * @return void - */ public function loginForm(Request $request) { - $validatedData = $request->validate([ + $rules = [ 'email' => 'required|email', 'password' => 'required', - ]); - return redirect('login')->with('status', 'Submitted.'); + ]; + + $messages = [ + 'email.required' => 'Your email address is required.', + 'password.required' => 'Your password is required.', + ]; + + $validator = Validator::make($request->all(), $rules, $messages); + + if ($validator->fails()) { + //return redirect('login') + return Redirect::back() + ->withErrors($validator) + ->withInput(); + } + + //$validatedData = $request->validate([ + //'email' => 'required|email', + //'password' => 'required', + //]); + //return redirect('login')->with('status', 'Submitted.'); + return Redirect::back()->with('status', 'Submitted.'); } diff --git a/database/factories/PostFactory.php b/database/factories/PostFactory.php index 0b00530..ea950a1 100644 --- a/database/factories/PostFactory.php +++ b/database/factories/PostFactory.php @@ -22,7 +22,7 @@ class PostFactory extends Factory public function definition() { return [ - 'title' => $this->faker->title, + 'title' => $this->faker->word, 'author' => $this->faker->name, 'text' => $this->faker->text, ]; diff --git a/resources/views/pages/index.blade.php b/resources/views/pages/index.blade.php index 1b7974f..eed53ac 100644 --- a/resources/views/pages/index.blade.php +++ b/resources/views/pages/index.blade.php @@ -39,7 +39,7 @@ It is consisted of the management building, 3 groups of bungalows, auxiliary facilities, sports courts and the following contents. -“Čardak“is surrounded by paths which are marked by information boards, +“Čardak“ is surrounded by paths which are marked by information boards, resting places and viewpoints. It provides a complete stay in the nature for school children, university students and especially experts in biological sciences. diff --git a/resources/views/pages/login.blade.php b/resources/views/pages/login.blade.php index bb1b7c8..b323872 100644 --- a/resources/views/pages/login.blade.php +++ b/resources/views/pages/login.blade.php @@ -10,14 +10,14 @@ @csrf
- + @error('email')
{{ $message }}
@enderror
- + @error('password')
{{ $message }}
@enderror diff --git a/resources/views/pages/reserve.blade.php b/resources/views/pages/reserve.blade.php index 26003b8..163fea0 100644 --- a/resources/views/pages/reserve.blade.php +++ b/resources/views/pages/reserve.blade.php @@ -11,7 +11,7 @@
- @error('scall') @@ -22,7 +22,7 @@
- + @error('sdate')
{{ $message }}
@enderror @@ -30,7 +30,7 @@
- + @error('stime')
{{ $message }}
@enderror @@ -39,7 +39,7 @@
- + @error('edate')
{{ $message }}
@enderror @@ -47,7 +47,7 @@
- + @error('etime')
{{ $message }}
@enderror @@ -177,7 +177,7 @@
- + @error('ocall')
{{ $message }}
@enderror @@ -186,7 +186,7 @@
- + @error('oname')
{{ $message }}
@enderror @@ -195,7 +195,7 @@
- + @error('email')
{{ $message }}
@enderror @@ -204,7 +204,7 @@
- + @error('phone')
{{ $message }}
@enderror -- cgit v1.2.3