PHP code example of coreplex / crumbs

1. Go to this page and download the library: Download coreplex/crumbs 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/ */

    

coreplex / crumbs example snippets


$container = new Coreplex\Crumbs\Container(new Coreplex\Crumbs\Components\Crumb, new Coreplex\Crumbs\Renderers\Basic);

$container->append('Homepage', '/home');

$container->prepare(function($crumbs)
{
    $crumbs->append('Homepage', '/home')
           ->append('Edit');
});

$container->prepend('The Website', '/');

echo $container->render();

echo $container->render(false);

echo $container;

$container->append('The Website', '//www.website.com');

foreach ($container->crumbs() as $crumb) {
    var_dump($crumb->label()); // returns 'The Website'
    var_dump($crumb->url()); // returns '//www.website.com'
    var_dump($crumb->current()); // returns true
}

// Append an empty breadcrumb to the container
$container->append();

foreach ($container->crumbs() as $crumb) {
    var_dump($crumb->label()); // returns null

    if ( ! $crumb->hasLabel()) {
        $crumb->setLabel('The Website')
    }

    var_dump($crumb->url()); // returns null

    if ( ! $crumb->hasUrl()) {
        $crumb->setUrl('//www.website.com')
    }

    var_dump($crumb->current()); // returns true

    if ( ! $crumb->current()) {
        $crumb->setCurrent();
    }

    $crumb->setNotCurrent();

    var_dump($crumb->current()); // returns false
}

'providers' => [

    'Coreplex\Crumbs\CrumbsServiceProvider',

]

/**
 * Make a new controller instance
 *
 * @param \Coreplex\Crumbs\Contracts\Container $breadcrumbs
 * @return void
 */
public function __construct(\Coreplex\Crumbs\Contracts\Container $breadcrumbs)
{
    $this->breadcrumbs = $breadcrumbs;
}

'aliases' => [

    'Crumbs' => 'Coreplex\Crumbs\Facades\Crumbs',

],

use Crumbs;

class DashboardController extends Controller {

    public function index()
    {
        Crumbs::prepare(function($crumbs)
        {
            $crumbs->append('Dashboard Home', route('dashboard.index'));
        });

        return view('dashboard.index')->with('breadcrumbs', Crumbs::render());
    }

}