Skip to content

Commit 2bef4d7

Browse files
committed
polish texts for first step in Getting Started widget
1 parent d8227ef commit 2bef4d7

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/resources/views/base/inc/getting_started.blade.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<p>
1616
<code class="text-primary bg-light p-1 rounded">php artisan backpack:crud user</code>
1717
</p>
18-
<p>Go ahead, run it. You'll notice it has:</p>
18+
<p>Go ahead, run it in your terminal. You'll notice it has:</p>
1919
<ul>
2020
<li>added an item to the sidebar, in <code class="text-primary bg-light p-1 rounded">resources/views/vendor/backpack/base/inc/sidebar_content.blade.php</code></li>
2121
<li>added a route, inside <code class="text-primary bg-light p-1 rounded">routes/backpack/custom.php</code></li>
@@ -28,12 +28,15 @@
2828

2929
<div class="collapse" id="customizeUsersCRUD">
3030
<p><strong>1. Let's remove the "password" column</strong> - no point in showing it. To do that, go to <code class="text-primary bg-light p-1 rounded">UserCrudController::setupListOperation()</code> and remove the line saying <code class="text-primary bg-light p-1 rounded">CRUD::column('password');</code>. Easy-peasy, right?</p>
31-
<p><strong>2. On Create & Update, let's add validation to forms</strong>. There are <a href="https://backpackforlaravel.com/docs/5.x/crud-operation-create#validation" target="_blank">multiple ways to add validation</a>, but for this simple example, let's just use <a href="https://backpackforlaravel.com/docs/5.x/crud-operation-create#validating-fields-using-field-attributes" target="_blank">field attribute validation</a>:</p>
31+
<p><strong>2. On Create & Update, let's add validation to forms</strong>. There are <a href="https://backpackforlaravel.com/docs/5.x/crud-operation-create#validation" target="_blank">multiple ways to add validation (A, B, C)</a>. Let's change the standard <a href="https://backpackforlaravel.com/docs/5.x/crud-operation-create#validating-fields-using-formrequests" target="_blank">validation using FormRequests</a> (A), to a simpler validation using <a href="https://backpackforlaravel.com/docs/5.x/crud-operation-create#validating-fields-using-field-attributes" target="_blank">field attributes</a> (C):</p>
3232
<ul>
33-
<li>inside <code class="text-primary bg-light p-1 rounded">UserCrudController</code>, let's remove <code class="text-primary bg-light p-1 rounded">use App\Http\Requests\UserRequest;</code> from the top;</li>
34-
<li>inside <code class="text-primary bg-light p-1 rounded">UserCrudController</code>, let's remove <code class="text-primary bg-light p-1 rounded">CRUD::setValidation(UserRequest::class);</code> from <code class="text-primary bg-light p-1 rounded">setupCreateOperation()</code>;</li>
35-
<li>let's delete the <code class="text-primary bg-light p-1 rounded">App\Http\Requests\UserRequest;</code> file;</li>
36-
<li>now we're left with zero validation inside <code class="text-primary bg-light p-1 rounded">UserCrudController</code>;</li>
33+
<li>to remove the current validation:<br>
34+
<ul>
35+
<li>inside <code class="text-primary bg-light p-1 rounded">UserCrudController</code>, remove <code class="text-primary bg-light p-1 rounded">use App\Http\Requests\UserRequest;</code> from the top;</li>
36+
<li>inside <code class="text-primary bg-light p-1 rounded">UserCrudController</code>, remove <code class="text-primary bg-light p-1 rounded">CRUD::setValidation(UserRequest::class);</code> from <code class="text-primary bg-light p-1 rounded">setupCreateOperation()</code>;</li>
37+
<li>delete the <code class="text-primary bg-light p-1 rounded">App\Http\Requests\UserRequest;</code> file;</li>
38+
</ul>
39+
</li>
3740
<li>a quick way to add validation is to go to <code class="text-primary bg-light p-1 rounded">setupCreateOperation()</code> and specify validation rules directly on the fields:
3841
<p>
3942
<pre class="text-primary bg-light p-1 rounded">
@@ -44,7 +47,7 @@
4447
</p>
4548
</li>
4649
</ul>
47-
<p><strong>3. On Create, let's hash the password.</strong> Ok so... now that we have basic validation, if we create a new User, it'll work. But if you look in the database... you'll notice the password is stored in plain text. We don't want that - we want it hashed. There are multiple ways to achieve this - inside the Model, the Request or the CrudController. Let's use Model Events inside UserCrudController. Here's how our <code class="text-primary bg-light p-1 rounded">setupCreateOperation()</code> would look, with the validation above rules and us tapping into the <code class="text-primary bg-light p-1 rounded">creating</code> event, to hash the password:</p>
50+
<p><strong>3. On Create, let's hash the password.</strong> Currently, if we create a new User, it'll work. But if you look in the database... you'll notice the password is stored in plain text. We don't want that - we want it hashed. There are <a href="https://backpackforlaravel.com/docs/5.x/crud-operation-create#use-events-in-your-setup-method" target="_blank">multiple ways to achieve this too</a>. Let's use Model Events inside <code class="text-primary bg-light p-1 rounded">setupCreateOperation()</code>. Here's how our method could look, when we also tap into the <code class="text-primary bg-light p-1 rounded">creating</code> event, to hash the password:</p>
4851
<p>
4952
<pre class="text-primary bg-light p-1 rounded">
5053
protected function setupCreateOperation()
@@ -59,7 +62,7 @@ protected function setupCreateOperation()
5962
}
6063
</pre>
6164
</p>
62-
<p><strong>4. On Update, let's not require the password</strong>. It should only be needed if an admin wants to change it, right? That means the validation rules will be different for "password". But it'll also be different for "email" (on Update we need to pass the ID to the unique rule in Laravel). Since 2/3 rules are different, let's just delete what was inside <code class="text-primary bg-light p-1 rounded">setupUpdateOperation()</code> and code it from scratch:</p>
65+
<p><strong>4. On Update, let's not require the password</strong>. It should only be needed if an admin wants to change it, right? That means the validation rules will be different for "password". But then again... the rules will also be different for "email", right? On Update, we need to pass the ID to the unique rule in Laravel. Since 2/3 rules are different, let's just delete what was inside <code class="text-primary bg-light p-1 rounded">setupUpdateOperation()</code> and code it from scratch:</p>
6366
<p>
6467
<pre class="text-primary bg-light p-1 rounded">
6568
protected function setupUpdateOperation()
@@ -78,7 +81,9 @@ protected function setupUpdateOperation()
7881
}
7982
</pre>
8083
</p>
81-
<p>That's it. You have a working Users CRUD. Plus, you've already learned some not-so-easy-to-do things, like using Model events inside CrudController and using field-validation instead of form-request-validation. Of course, this only scratches the surface of what Backpack can do. So we heavily recommend you move on to the next step, and learn the basics.</p>
84+
<p>
85+
That's it. You have a working Users CRUD. Plus, you've already learned some advanced techniques, like <a href="https://backpackforlaravel.com/docs/5.x/crud-operation-create#use-events-in-your-setup-method" target="_blank">using Model events inside CrudController</a> and <a href="https://backpackforlaravel.com/docs/5.x/crud-operation-create#b-validating-fields-using-a-rules-array" target="_blank">using field-attribute-validation instead of form-request-validation</a>. Of course, this only scratches the surface of what Backpack can do. To really understand how it works, and how you can best use Backpack's features, <strong>we heavily recommend you move on to the next step, and learn the basics.</strong>
86+
</p>
8287
</div>
8388
</div>
8489
</div>

0 commit comments

Comments
 (0)