mjanssen / Laravel-5-breadcrumbs-bundle

A simple solution for breadcrumbs in Laravel 5+
15 stars 7 forks source link

Fatal error : Class 'Breadcrumbs' not found on view #6

Closed sachinvrg closed 9 years ago

sachinvrg commented 9 years ago

Hello,

I have setup all the stuffs you mentioned here, but when I call breadcrumbs on view, it is giving fatal error Class 'Breadcrumbs' not found.

can you please help me, I am using laravel 5.1

mjanssen commented 9 years ago

I'll look into it :)

sachinvrg commented 9 years ago

Thank you for consider my issue, may be you want to have a look at my controller, here it is <?php namespace App\Modules\Admin\Controllers;

use App\Http\Requests; use App\Http\Controllers\Controller;

use Illuminate\Http\Request; use mjanssen\BreadcrumbsBundle\Breadcrumbs; use Session,Auth,Redirect,Lang,Config,App;

class AdminController extends Controller {

public function __construct()
{
    if(!(Auth::user()))
    {
        Redirect::to('login')->send();
    }
}

/**
 * Display a listing of the resource.
 *
 * @return Response
 */
public function index()
{
    Breadcrumbs::addBreadcrumb('Dashboard', '/admin');
    Breadcrumbs::addBreadcrumb('Second crumb', '/second-page');

    return view("admin::index");
}

public function logout()
{
    Auth::logout();
    return redirect('login');
} 

}

sachinvrg commented 9 years ago

on my view I have this - {{ Breadcrumbs::generate() }}

mjanssen commented 9 years ago

Ahh, consider pushing your data from the controller to the view.

That would be

$data = [
    'breadcrumbs' => Breadcrumbs::generate()
]

return view("admin::index", $data);

//Your view
{{ $breadcrumbs }} // Is an ol tag including your breadcrumbs

By default the view should only be used for displaying breadcrumbs and not generating them (logic should be handled in your controller).

Let me know if it works out like this :)

sachinvrg commented 9 years ago

Hello mjanssen, your following code was giving syntax error - $data = [ 'breadcrumbs' => Breadcrumbs::generate() ] then I change it to - $data['breadcrumbs'] = Breadcrumbs::generate();

and return view("admin::index",$data);

but on my view it is showing complete HTML in place of breadcrumb - please check attached screen shot. breadcrumb

mjanssen commented 9 years ago

Whoops! Try {!! $breadcrumbs !!} in your view, that should do the trick. Laravel escapes HTML code while using {{}} vars.

sachinvrg commented 9 years ago

Thank you very much mjanssen, now it is showing breadcrumbs, but not properly formated, I think there must be some class for it, if you know then please let me know class name and how can I set it? Thanks again. breadcumb-format

mjanssen commented 9 years ago

I suppose you added the config file (config/breadcrumbs.php (https://github.com/mjanssen/Laravel-5-breadcrumbs-bundle/blob/master/config_file_breadcrumbs.php for an example)).

In this file you can set the class which is used by the

    tag. By default it uses bootstrap CSS classes, which can be altered to your own wishes.

    Let me know if this works for you :)

sachinvrg commented 9 years ago

Thank you very much man, you are genius :+1:
I didn't find breadcrumbs.php file in my config directory but I added 'breadcrumb' class directly to ol tag, and it is looking nice :)