> For the complete documentation index, see [llms.txt](https://pratikdai404.gitbook.io/adminetic/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pratikdai404.gitbook.io/adminetic/example-walkthrough.md).

# Example Walkthrough

In this walkthrough we will make quotes module using super powers of adminetic admin panel

## Let's get started

Lets make **`quotes`** module using crud generator/

```
php artisan make:crud Quote --acl
```

We will get output as follows

```
Controller created successfully ... ✅
Model created successfully ... ✅
Index file created successfully ... ✅
Create file created successfully ... ✅
Edit file created successfully ... ✅  
Show file created successfully ... ✅  
Edit add extended file created successfully ... ✅
Script file created successfully ... ✅
Migration file created named create_quotes_table ... ✅
Seeder file created ... ✅
Repository and Interface created ... ✅
Request file created ... ✅
ACL created ... ✅
CRUD made for model Quote ... ✅
```

#### So what did adminetic admin panel generated for us ?

1. Quote Model on app/Models/Admin/Quote.
2. Quote Controller on app/Http/Controllers/Admin/QuoteController
3. Index, Edit, Create and Show blade views in resources/views/admin/quote folder
4. edit\_add and script layout blade file in resources/views/admin/layouts/module/quote folder
5. create\_*quotes\_*&#x74;able in database/migrations folder
6. QuotesSeeder file in database/seeder folder
7. QuoteRepository class in app/Repositories filder
8. QuoteInterface interface in app/Contracts
9. QuoteRequest in app/Http/Requests folder
10. QuotePolicy in app/Policies folder
11. Permission Generation for Quote module

#### lets hookup our quote module

&#x20;Go to our **`AdminServiceProvider`** in app/Providers folder and bind quote interface and repository in repos method in our provider

```
  protected function repos()
    {
        $this->app->bind(QuoteRepositoryInterface::class, QuoteRepository::class);
    }
```

{% hint style="info" %}
**Note** don't forget to register our provider in config/app file
{% endhint %}

#### lets register our routes in web.php

```
use App\Http\Controllers\Admin\QuoteController;

Route::group(['prefix' => config('adminetic.prefix', 'admin'), 'middleware' => config('adminetic.middleware')], function () {
    Route::resource('quote', QuoteController::class);
});
```

{% hint style="info" %}
Note admin route must be under prefix **admin** and middleware **auth** and **web**
{% endhint %}

#### Lets create out database schema

In our database/migrations folder go to our newly created migration create\_*quotes\_*&#x74;able

```
   public function up()
    {
        Schema::create('quotes', function (Blueprint $table) {
            $table->id();
            $table->string('quote');
            $table->timestamps();
        });
    }
```

#### Lets migrate our schema

```
php artisan migrate
```

#### Lets work on validating our requests in app/Htpp/Requests/QuoteRequest.php

```
class QuoteRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'quote' => 'required|max:255'
        ];
    }
}
```

#### Lets create our form in admin/layouts/module/quote/edit*add\_*&#x62;lade.php

```
<div class="row">
    <div class="col-lg-12">
        <div class="mb-3" style="position: static;">
            <label for="quote">Quote</label>
            <input name="quote" class="form-control btn-square" id="quote" type="text" placeholder="Enter Quote"
                value="{{ $quote->quote ?? old('quote') }}" placeholder="please enter your quote">
        </div>
    </div>
</div>
<x-adminetic-edit-add-button :model="$quote ?? null" name="Quote" />
```

here edit\_add view acts as a extends view form for both create and edit view. so \<x-admientic-edit-add-button :model="$quote ?? null" name="Quote" /> componen is used as a submit button that works for both form.. Instead of edit-add-button component you can also use

```
   <input type="submit"
        class="btn btn-{{ isset($quote) ? 'warning' : 'primary' }} btn-air-{{ isset($quote) ? 'warning' : 'primary' }}"
        value="{{ isset($model) ? 'Edit Quote' : 'Add Quote'}}">
```

#### Lets register our route to menu. In app/Services/MyMenu.php on myMenu method add folowing to array

```
return [
  [
                'type' => 'menu',
                'name' => 'Quotes',
                'icon' => 'fa fa-quote-right',
                'is_active' => request()->routeIs('quote*') ? 'active' : '',
                'pill' => [
                    'class' => 'badge badge-info badge-air-info',
                    'value' => "plugin",
                ],
                'conditions' => [
                    [
                        'type' => 'or',
                        'condition' => auth()->user()->can('view-any', App\Models\Admin\Quote::class),
                    ],
                    [
                        'type' => 'or',
                        'condition' => auth()->user()->can('create', App\Models\Admin\Quote::class),
                    ],
                ],
                'children' => $this->indexCreateChildren('quote', App\Models\Admin\Quote::class)
            ],
];
```

#### Hurray our quote module is complete.

#### What are the advantages ?

* BREAD ACL is made
* Repository Pattern Architecture Followed
* Consistent Coding
* Query Caching enabled ...&#x20;
