Package Data | |
---|---|
Maintainer Username: | jzpeepz |
Maintainer Contact: | jonathan@flex360.com (Jonathan Peoples) |
Package Create Date: | 2016-08-29 |
Package Last Update: | 2021-12-10 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-23 03:09:01 |
Package Statistics | |
---|---|
Total Downloads: | 1,606 |
Monthly Downloads: | 14 |
Daily Downloads: | 3 |
Total Stars: | 1 |
Total Watchers: | 4 |
Total Forks: | 0 |
Total Open Issues: | 2 |
Install via Composer:
composer require jzpeepz/dynamo
Include the service provider in your config/app.php
:
Jzpeepz\Dynamo\DynamoServiceProvider::class
Publish the Dynamo config file:
php artisan vendor:publish --tag=dynamo
NOTE: If using a local disk for uploading, be sure to symlink it to your public directory and provide the proper path in the config file.
storage_disk
Storage disk to use to store uploaded files. Default: 'local'
upload_path
Path within the storage disk to store the uploaded files. This is also the directory within the public directory to which the storage directory is linked. Default: '/uploads/'
route_prefix
Prefix to add to all Dynamo routes. Default: '' (empty string)
layout
Layout to use with Dynamo views. Default: 'layouts.app'
controller_namespace
Namespace for generated controllers. Default: 'App\Http\Controllers'
controller_path
Path for storing generated controllers. Default: app_path('/Http/Controllers')
view_prefix
Prefix for overridden views. Default: 'dynamo'
view_theme
Theme used for views. Default: 'bootstrap4'
target_blade_section
The blade section in templates where views are rendered. Default: 'content'
default_has_many_class
CSS class used by default on hasMany field types. Default: ''
model_uses
This value contains an array of the classes that should be imported into the generated model class. Default: []
model_implements
This value contains an array of the interfaces that should be implemented by the generated model class. Default: []
model_traits
This value contains an array of the traits that should be used by the generated model class. Default: []
The following command will create a controller, model, migration, and route for your admin:
php artisan make:dynamo Employee
Need to opt out of some of the Dynamo magic?
php artisan make:dynamo Employee --migration=no --model=no --controller=no --route=no
Admin customization happens in your controller inside the getDynamo()
function. This function returns a Dynamo instance which has lots of chainable methods that customize your Dynamo admin. Below are methods you can chain.
By default, Dynamo will add all fields from the database table to the index. Removing the call to auto()
in the getDynamo()
method in the generated controller, will stop all fields from getting added to the index AND the form.
addIndex($key, $label = null, $formatCallable = null)
This method allows you to add or update an index column.
Parameters:
$key
This is the column name in your database table if you are hoping to populate it with table data. Otherwise, it could be any unique name.
$label
(optional) This is pretty name you want folks to see.
$formatCallable
(optional) This is a closure that allows you to completely customize how the index column renders. This closure will receive one parameter of the Eloquent instance for that row. The closure should return what you would like to render in the index column.
removeIndex($key)
This method allow you to remove a column from the index.
Parameters:
$key
This is the key used to create the index. It is typical the column name in the database table.
clearIndexes()
This method removes all index columns. This can be used to clear indexes create by auto()
while leaving the form fields in place.
indexOrderBy($column, $sort = 'asc')
This method allows you to order the rows returned from the database.
paginate($limit)
This method allows you to set the number of rows to display on each page of the index.
return Dynamo::make(\App\Employee::class)
->group(FieldGroup::make('groupName')
->text('fieldName')
->text('fieldName');
});
Step 1: Generate the two models you will be using.
php artisan make:dynamo Faq
php artisan make:dynamo Category
Step 2: Complete the needed migrations.
Example Faq migration:
Schema::create('faqs', function (Blueprint $table) {
$table->increments('id');
$table->string('question', 255);
$table->mediumText('answer');
$table->timestamps();
});
Example Category migration:
Schema::create('categories', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
Example pivot table migration:
Schema::create('category_faq', function(Blueprint $table)
{
$table->integer('faq_id')->unsigned()->nullable();
$table->foreign('faq_id')->references('id')->on('faqs');
$table->integer('category_id')->unsigned()->nullable();
$table->foreign('category_id')->references('id')->on('categories');
});
Run php artisan migrate
.
Step 3: Add the proper belongsToMany Eloquent function to each model.
For the Category model:
public function faqs()
{
return $this->belongsToMany('App\Faq');
}
For the Faq Model:
public function categories()
{
return $this->belongsToMany('App\Category');
}
Step 4: Chain the hasMany()
method onto your Dynamo instance in both controllers. Make sure your key is the name of the Eloquent function from you model.
return Dynamo::make(\App\Employee::class)
->hasMany('categories', ['options' => [$categories]]);
https://dynamo-admin.readthedocs.io/en/latest/index.html
Dynamo is open-sourced software licensed under the MIT license.