Skip to content
This repository was archived by the owner on Sep 17, 2018. It is now read-only.

Laravel and Bard

Mario Basic edited this page Mar 31, 2015 · 8 revisions

Dependency injection in Laravel

<?php namespace App\Http\Controllers;

use Carbon\Carbon;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Laravelista\Bard\UrlSet as Sitemap;

class SitemapController {

    protected $sitemap;

    public function __construct(Sitemap $sitemap) 
    {
        $this->sitemap = $sitemap;
    }

    public function generate()
    {
        $home = $this->sitemap->addUrl(route('home'));
        $home->setPriority(0.8);
        $home->setChangeFrequency('hourly');
        $home->setLastModification(Carbon::now());
        $home->addTranslation("de", route('home'));

        $this->sitemap->addUrl(
            route('contact'), 
            0.7, 
            'monthly', 
            Carbon::now(), 
            [
                [
                    "hreflang" => 'de', 
                    'href' => route('contact')
                ]
            ]
        );

        $this->sitemap->addUrl(route('gallery'));

        return $this->sitemap->render();
    }

}

Resolve out of Service Container IoC in Laravel

$sitemap = App::make('Laravelista\Bard\Sitemap')
Clone this wiki locally