Package for laravel-admin.
Via Composer
$ composer require denis-kisel/laravel-admin-widget
Add service provider in the config/app.php file. Optional for laravel5.4+
/*
* Package Service Providers...
*/
DenisKisel\LaravelAdminWidget\LaravelAdminWidgetServiceProvider::class,
Make publish
$ php artisan vendor:publish --provider="DenisKisel\\LaravelAdminWidget\\LaravelAdminWidgetServiceProvider"
Run migration
$ php artisan migrate
Command: php artisan admin:widget {name}
$ php artisan admin:widget Slider
This command will generate file by path: app/Admin/Controllers/Widgets/SliderWidget.php.
And will add route site.com/admin/slider-widget
Get widget data as array:
<?php
use DenisKisel\LaravelAdminWidget\Facade\Widget;
Widget::getArray($code)
Get widget data as collection
<?php
use DenisKisel\LaravelAdminWidget\Facade\Widget;
Widget::getCollection($code)
Also possible put custom data
<?php
use DenisKisel\LaravelAdminWidget\Facade\Widget;
Widget::put($code, $data) #Store or update widget
For Sortable Items I use jquery-ui lib.
{items} - Is NestedForm Key
Admin::js('/js/admin/jquery-ui.min.js');
Admin::script('$(function() {
$(\'.has-many-{items}-forms\').sortable();
});');
Live Example:
public function form()
{
Admin::js('/js/admin/jquery-ui.min.js');
Admin::script('$(function() {
$(\'.has-many-items-forms\').sortable();
});');
$data = Widget::getArray($this->code);
$form = new \Encore\Admin\Widgets\Form($data);
$form->repeat('items', function (NestedForm $form) {
$form->textarea('title', __('admin.title'));
$form->image('image', __('admin.image'));
});
$form->action(url()->current());
return $form->render();
}
Call to a member function getKey()
For fix this error, just run:
php artisan fix:nested_form