Skip to content

Commit 30aef2d

Browse files
author
G
committed
Updates to Instructions page
1 parent 6c4d6c7 commit 30aef2d

File tree

3 files changed

+71
-24
lines changed

3 files changed

+71
-24
lines changed

app/Providers/FormServiceProvider.php

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ class FormServiceProvider extends ServiceProvider
1717
public function register()
1818
{
1919
$this->app->bind(ReCaptchaV3::class, function ($app) {
20-
2120
return new ReCaptchaV3(new Client(), env('RECAPTCHA_SECRET'), \Log::getLogger(), null);
2221
});
2322
}

app/helpers.php

-8
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,6 @@ function attributeTemplate($view, $attributes = [])
3131

3232
/**
3333
* Used on a laravelcollective/html form to iterate through an array of fields
34-
*
35-
* @param string $field
36-
* @param \Illuminate\Database\Eloquent\Model|null $model
37-
* @return array
3834
*/
3935
function formIterator(?Eloquent\Model $model, string $field): array
4036
{
@@ -45,10 +41,6 @@ function formIterator(?Eloquent\Model $model, string $field): array
4541

4642
/**
4743
* Used on a laravelcollective/html form to provide JavaScript with next key to use when adding to array of fields
48-
*
49-
* @param \Illuminate\Database\Eloquent\Model|null $model
50-
* @param string $parentField
51-
* @return int
5244
*/
5345
function nextKey(?Eloquent\Model $model, string $parentField): int
5446
{

resources/views/tutorial/instructions.blade.php

+71-15
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
The source code for this website can be found at <a href="{{ $gitHubRepo }}">GitHub</a>.
2121
</p>
2222
<p>
23-
Below are instruction on how to set up in Laravel 7 <a href="/en_US/programmer/create">this dynamic form here</a>.
23+
Below are instruction on how to set up in Laravel 8 <a href="/en_US/programmer/create">this dynamic form here</a>.
2424
The form contains several dynamic sections (fields added by JavaScript). It also has dynamic elements within
2525
other dynamic blocks. This makes building and validating the form more complex. Some quite complex validation
2626
rules are applied.
@@ -32,7 +32,7 @@
3232
</p>
3333
<ul>
3434
<li>
35-
Have a working instance of Laravel 7
35+
Have a working instance of Laravel 8
3636
</li>
3737
<li>
3838
Install Laravel Collective and create some form components
@@ -56,7 +56,42 @@
5656
<br>
5757
These files should be customized for your projects particular needs.
5858
</li>
59-
<li>app/Providers - add <a href="{{ $gitHubRepo }}/blob/master/app/Providers/FormServiceProvider.php">FormServiceProvider.php</a></li>
59+
<li>app/Providers - add FormServiceProvider.php as follows:
60+
<pre>
61+
&lt;?php
62+
63+
namespace App\Providers;
64+
65+
use Illuminate\Support\ServiceProvider;
66+
use Form;
67+
68+
class FormServiceProvider extends ServiceProvider
69+
{
70+
/**
71+
* Register services.
72+
*
73+
* @return void
74+
*/
75+
public function register()
76+
{
77+
}
78+
79+
/**
80+
* Bootstrap services.
81+
*
82+
* @return void
83+
*/
84+
public function boot()
85+
{
86+
Form::component('myInput', 'components.form.myInput', ['type', 'name', 'value' => null, 'attributes' => []]);
87+
Form::component('myTextarea', 'components.form.myTextarea', ['name', 'value' => null, 'attributes' => []]);
88+
Form::component('mySelect', 'components.form.mySelect', ['name', 'options', 'value' => null, 'attributes' => []]);
89+
Form::component('myCheckboxList', 'components.form.myCheckboxList', ['name', 'options', 'attributes' => []]);
90+
Form::component('myRadioList', 'components.form.myRadioList', ['name', 'options', 'attributes' => []]);
91+
}
92+
}
93+
</pre>
94+
</li>
6095
<li>config/app.php - add App\Providers\FormServiceProvider::class to 'providers' array</li>
6196
</ul>
6297
</li>
@@ -256,7 +291,7 @@ function languageSwitch()
256291
public function add(\App\Model\ProgrammingExperienceFormOptions $formOptions)
257292
{
258293
return view('programmer/edit', [
259-
'countries' => $formOptions->getCountries('en_US'),
294+
'countries' => $formOptions->getCountries(request('locale', 'en_US')),
260295
'languages' => $formOptions->getProgrammingLanguages(),
261296
'workTypes' => $formOptions->getWorkTypeOptions(),
262297
]);
@@ -324,10 +359,6 @@ function attributeTemplate($view, $attributes=[])
324359

325360
/**
326361
* Used on a laravelcollective/html form to iterate through an array of fields
327-
*
328-
* @param string $field
329-
* @param \Illuminate\Database\Eloquent\Model|null $model
330-
* @return array
331362
*/
332363
function formIterator(?Eloquent\Model $model, string $field): array
333364
{
@@ -474,10 +505,6 @@ function formIterator(?Eloquent\Model $model, string $field): array
474505
<pre>
475506
/**
476507
* Used on a laravelcollective/html form to provide JavaScript with next key to use when adding to array of fields
477-
*
478-
* @param \Illuminate\Database\Eloquent\Model|null $model
479-
* @param string $parentField
480-
* @return int
481508
*/
482509
function nextKey(?Eloquent\Model $model, string $parentField): int
483510
{
@@ -528,6 +555,9 @@ function nextKey(?Eloquent\Model $model, string $parentField): int
528555
<li>
529556
Follow the instructions from reCAPTCHA to install Version 2 onto the form
530557
</li>
558+
<li>
559+
In the .env file add the reCAPTCHA key (as RECAPTCHA_KEY) and secret (as RECAPTCHA_SECRET).
560+
</li>
531561
<li>
532562
To show an error message when reCAPTCHA fails to verify the user is human place the following
533563
code at the top of the form
@@ -551,7 +581,33 @@ function nextKey(?Eloquent\Model $model, string $parentField): int
551581
I have moved it into the Repository directory.
552582
</li>
553583
<li>
554-
Create the class <a href="{{ $gitHubRepo }}/blob/master/app/Model/ReCaptchaV3.php">App\Model\ReCaptchaV3</a>.
584+
Create the validator for reCAPTCHA:
585+
<ul>
586+
<li>
587+
In composer.json require - "guzzlehttp/guzzle": "^7.0.1"
588+
<br>
589+
Command: composer update
590+
</li>
591+
<li>
592+
Create the class <a href="{{ $gitHubRepo }}/blob/master/app/Entity/IpAddress.php">App\Entity\IpAddress</a>.
593+
</li>
594+
<li>
595+
Create the class <a href="{{ $gitHubRepo }}/blob/master/app/Model/ReCaptchaV3.php">App\Model\ReCaptchaV3</a>.
596+
</li>
597+
<li>
598+
In App\Providers\FormServiceProvider above the class declaration add:<br>
599+
use App\Model\ReCaptchaV3;<br>
600+
use GuzzleHttp\Client;<br>
601+
<br>
602+
In the register() method add:
603+
<pre>
604+
$this->app->bind(ReCaptchaV3::class, function ($app) {
605+
return new ReCaptchaV3(new Client(), env('RECAPTCHA_SECRET'), \Log::getLogger(), null);
606+
});
607+
</pre>
608+
The reCAPTCHA secret (RECAPTCHA_SECRET) is to be held in the .env file.
609+
</li>
610+
</ul>
555611
</li>
556612
<li>
557613
Run command "php artisan make:request ProgrammingExperienceSave" to create the file
@@ -561,7 +617,7 @@ class in it. This class will contain the form validation logic.
561617
Add the contents from the
562618
<a href="{{ $gitHubRepo }}/blob/master/app/Http/Requests/ProgrammingExperienceSave.php" target="_blank">GitHub Repository</a>
563619
to this file. The code here is quite self-explanatory if you are already familiar with writing
564-
<a href="https://laravel.com/docs/7.x/validation" target="_blank">Laravel Validation logic</a>.
620+
<a href="https://laravel.com/docs/8.x/validation" target="_blank">Laravel Validation logic</a>.
565621
</li>
566622
<li>
567623
Above the Controller (i.e. ProgrammerExperienceController) add the lines:
@@ -614,7 +670,7 @@ public function edit(FormOptions $formOptions)
614670

615671
return view('programmer/edit', [
616672
'personExperience' => $personExp,
617-
'countries' => $formOptions->getCountries('en_US'),
673+
'countries' => $formOptions->getCountries(request('locale', 'en_US')),
618674
'languages' => $formOptions->getProgrammingLanguages(),
619675
'workTypes' => $formOptions->getWorkTypeOptions(),
620676
]);

0 commit comments

Comments
 (0)