PHP code example of peyman3d / laravel-share

1. Go to this page and download the library: Download peyman3d/laravel-share library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

peyman3d / laravel-share example snippets


Peyman3d\Share::class,

'Share' => Peyman3d\Share\ShareFacade::class,

Share::make('Person')
	   ->add('name', 'Peyman')
	   ->add('email', '[email protected]')
	   ->add('job', 'Web developer')
	   ->edit('title', 'Mr');

share()->make('asset.js')->add('react', 'https://cdnjs.cloudflare.com/ajax/libs/react/16.4.0/umd/react.production.min.js')

// Change key
share()->key('menu');

// Make new item with key and value
share()->make($key, $value, $single);

// Create new item to current key
share()->make('menu')->item('dashboard');

// Prepend an item to current key
share()->make('menu')->prepend('posts');

// Add a child to array
share()->make('menu')->item('users')->child('users-list');

// Check if key exists
share()->key('menu')->has('dashboard');

// Get from array with key
// Second parameter is for get result as single value or collection
share()->key('menu')->get('users', true);

// Pull data from array and delete it
share()->key('menu')->pull('users', true);

// Get all data
share()->all();

// Delete data for current key
share()->key('menu.users')->delete();

// Delete all data
share()->reset();


share()->make('user')->add('profile', auth()->user());
share()->menu('posts')->add('filter', function($value){
    return '<h3>'.$value.'</h3>';   
});

share()->make('Job')->title('Senior Developer');

// Create new menu with items
share()->menu()->item('dashboard')->label('Dashboard')->href('/admin/');
share()->menu()->item('users')->label('Users')->route('admin.users');
share()->menu('users')->child('users-profile')->label('Profile')->route('admin.users.profile');
share()->menu('users')->child('users-list')->label('All users')->route('admin.users.index');
share()->menu('users')->child('users-create')->label('Add new user')->route('admin.users.create');

// Manage Assets
share()->js('jquery')->link('https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js')->order(500);
share()->js('react')->link('https://cdnjs.cloudflare.com/ajax/libs/react/16.4.0/umd/react.production.min.js')->order(300);

// Arguments
share()->addArg('avatar');
share()->removeArg('icon');
share()->editArg('subtitle', 'second-title');
if( share()->hasArg('config') ){
    share()->editArg('config', 'setting');
}

// Keys
share()->addKey('table');
share()->removeKey('view');
share()->editKey('asset', 'libraries');
if( share()->hasKey('menu') ){
    share()->editKey('menu', 'menus');
}

// Add dashboard
share()->menu()->item('dashboard')->label('Dashboard')->icon('fa fa-dashboard')->route('admin.dashboard');

// Add posts and it's sub items
share()->menu()->item('posts')->label('Posts')
               ->icon('fa fa-file-text-o')->route('admin.posts');
share()->menu('posts')->child('posts-list')->label('All posts')
                      ->route('admin.posts.index');
share()->menu('posts')->child('posts-create')->label('Add new post')
                      ->route('admin.posts.create');

// Add setting
share()->menu()->item('settings')->label('Settings')->icon('fa fa-cogs');
foreach($setting_pages as $page){
    share()->menu('settings')->child('setting-page-'.$page['id'])->label($page['label'])
                          ->route('admin.settings')
                          ->route_attributes(['slug'=>$page['slug']]);
}

// PostController.php

public function index(){
    share()->key('menu.posts')->activate();
    share()->key('menu.posts.children.posts-list')->activate();
}

// AdminMiddleware.php

class AdminMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        share()->key('menu.posts')->order(100);
    
	    return $next($request);
    }
}
blade
<aside id="sidebar">

    <ul class="menu">
    
        @foreach( share()->menu()->get() as $item )
        
            <li class="menu-item @if( array_has($item, 'children') ) has-child @endif @if(array_get($menu_item, 'active', false)) active @endif">
            
                <a href="{{ make_menu_link($item) }}">
                    <i class="{{ array_get($item, 'icon') }}"></i>
                    <span class="title">{{ array_get($item, 'label') }}</span>
                </a>

                @if( array_has($item, 'children') )
                    <ul class="sub-menu" @if(array_get($menu_item, 'active', false)) style="display: block;" @endif>
                        @foreach( $item['children'] as $subitem )
                            <li><a href="{{ make_menu_link($subitem) }}">{{ $subitem['label'] }}</a></li>
                        @endforeach
                    </ul>
                @endif

            </li>
        
        @endforeach
    
    </ul>

</aside>