Resources

Mainly, Lamotivo is an administration dashboard for a Laravel application. The main feature of Lamotivo is the ability to manage your Eloquent models through Lamotivo resources.

Creating Resources

Lamotivo resources are placed in the app/Lm directory. You may generate a new resource usign the lm:resource Artisan command. For example, we will create a resource for the App\Models\Product model:

php artisan lm:resource App\\Models\\Product

In the created Lamotivo resource you can find the public static $model property that defines an Eloquent model to use.

The lm:resource command also registers a newly created Lamotivo resource in the main menu at the bottom of the app/Lm/bootstrap.php file.

By default all resources are added to the main menu. If you want to hide a resource from the menu, you may change it like this:

// from this
lm()->menu()->resource(App\Lm\Tag::class);

// to this
lm()->resource(App\Lm\Tag::class);

It will register the resource, but will not place in the menu;

Grouping Resources

If you want to create a group in the main menu, you may call the group() method:

lm()->menu()->group('Services and Products', function($menu) {
    $menu->resource(App\Lm\Service::class);
    $menu->resource(App\Lm\Product::class);
    $menu->resource(App\Lm\Category::class);
    $menu->resource(App\Lm\Tag::class);
});

Resource Events

All typical resource operations pass through some methods on the resource:

  • saving
  • saved
  • creating
  • created
  • updating
  • updated
  • deleting
  • deleted

You may define them like this:

public function saving(Request $request, $model)
{
    // Do with the $model whatever you want
}

Also you may create a model event listener with a model observer.

Preventing Conflicts

It the model has been updated since the last retrieval, Lamotivo will respond with a 409 Conflict status code to prevent unintentional changes.

Pagination

All Lamotivo resources are paginated, by default.

You may customize the amount shown on resource's pages by changing the $per_page property.

protected static $per_page = 15;