Example Walkthrough
Lets see what's it like to work with adminetic admin panel
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 ?
Quote Model on app/Models/Admin/Quote.
Quote Controller on app/Http/Controllers/Admin/QuoteController
Index, Edit, Create and Show blade views in resources/views/admin/quote folder
edit_add and script layout blade file in resources/views/admin/layouts/module/quote folder
create_quotes_table in database/migrations folder
QuotesSeeder file in database/seeder folder
QuoteRepository class in app/Repositories filder
QuoteInterface interface in app/Contracts
QuoteRequest in app/Http/Requests folder
QuotePolicy in app/Policies folder
Permission Generation for Quote module
lets hookup our quote module
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);
}
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);
});
Lets create out database schema
In our database/migrations folder go to our newly created migration create_quotes_table
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/editadd_blade.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 ...
Last updated
Was this helpful?