Download the PHP package peyman3d/laravel-share without Composer
On this page you can find all versions of the php package peyman3d/laravel-share. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-share
Laravel Share
Laravel Share is an easy way to share any data through a request.
Introduction
With Laravel Share you can share any data through a request to use later. You should consider it as an array that are available everywhere. I mean EVERYWHERE! From Service Provider to routes, middlewares, controllers and views.
Installation
Install using Composer
When installation completes you should add provider and alias to config/app.php
file. If you are using Laravel 5.5 or 5.6 you can skip this step as Laravel can discover this package automatically.
-
Add to providers array:
- Add to alias array:
Usage
Using Laravel Share is easy as pie. Just think of a person and you can share data like this:
And when you want that data just use Share::get('Person');
;
As you see you can create an item with make()
method. then you can add parameters to it by using add($key, $value)
or edit($key, $value)
. You can also use share()
helper instead of Share
Facade.
There are some basic methods for working with data array:
What data can be shared?
Almost anything. You can share any string, numbers, objects and closures.
Even better helpers
Laravel Share has more helpers to create better syntax. You can use any combination of these helpers.
As you can see title()
method accept a value and work just like add('title', 'Senior Developer')
.
Check all helpers here:
id()
title()
subtitle()
label()
icon()
link()
route()
route_attributes()
href()
fallback()
callback()
order()
class()
desc()
type()
default()
options()
name()
placeholder()
children()
file()
src()
active()
config()
format()
permission()
count()
attributes()
field()
blade()
Other than this helpers for parameters, we also have some helpers for sections and types:
menu()
view()
asset()
js()
css()
script()
style()
You can check some examples:
Custom helpers
I added some basic helpers that works for me, but you can also add yours. You can remove or edit items too. See some examples below:
Just an example
Imagine you have an admin panel that has a menu on sidebar. This menu has multiple items and each one may have sub-items. Now, we add some items to the menu:
These codes can be anywhere: Service Provider, routes, middlewares, controller, model and even a blade view. If you want you can active a menu item like this:
And you can sort items with order()
method. It can be done when you add an item or just any other times and places.
If you don't set order, it counts as 100.
And finally you can use this data in a blade view like sidebar.blade.php
as simple as this:
And that's just it :)
Just one thing. I use a helper function called make_menu_link()
that I wrote for create item link base on what it has. It's not on the package as it may not be useful for you. But you can have it in this link.