Widget

Want custom widget with your styles and methods ? Custom widget may be generated using the atomic:widget Artisan command. By default, all new widgets will be placed in the atomic-components/widgets directory of your application:

php artisan atomic:widget Atomic/SimpleWidget
1

When generating a tool, Artisan will prompt you to update your application's composer.json file. All custom widgets are registered with your application as a Composer "path" repository. Widget name Atomic/SimpleWidget must be like laravel packages name/packagename so you can upload and share it with other developers ♥.

The generated folder will contain

  • routes.php Widget Routes
  • resources/views/widget.blade.php for widget html
  • src/SimpleWidget.php Widget Class
  • src/WidgetServiceProvider.php Widget Service Provider
  • src/Http/Controllers/WidgetController.php Widget Controller

routes.php

this contain widget routes

<?php

Route::post('/','WidgetController@action')->name('action');
1
2
3

WidgetController.php

The Controller for widget routes

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class WidgetController extends Controller
{

    /**
     * Widget Response
     * @return \Illuminate\Http\JsonResponse
     */
    public function action(Request $request)
    {
        flash('thanks ♥ for your request');
        return redirect()->back();
    }

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

SimpleWidget.php

Widget main class

use MustafaKhaled\AtomicPanel\AtomicPanel;
use MustafaKhaled\AtomicPanel\AtomicWidget;

class SimpleWidget extends AtomicWidget
{

    public $widgetCols = 3;


    /**
     * @param null $AtomicModel
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|null
     */
    public function render($AtomicModel = null)
    {
        return view(AtomicPanel::classNamespace(SimpleWidget::class) . '::widget')->with('widget', SimpleWidget::class)->with('model',$AtomicModel);
    }

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

you have render method with AtomicModel the reference of model class.

WidgetServiceProvider.php

The main provider for the widget to register routes and views , but the most important part in this file is:

 /**
  * @throws \ReflectionException
  */
 public function boot()
 {
     AtomicPanel::serving(function (ServingAtomic $event) {
         AtomicPanel::serveScripts([]);
         AtomicPanel::serveStyles([]);
     });
     parent::boot();
 }
1
2
3
4
5
6
7
8
9
10
11

you can use those methods

AtomicPanel::serveScripts([]);
AtomicPanel::serveStyles([]);
1
2

to register any styles or scripts for Atomic Panel layout