ziben69
130
3
Laravel

Displaying data from the table in all views

Posted 5 months ago by ziben69

Hello guys, i try to display data from one table in all views, but writing in each controller is very breakneck.

I created a view in which I display data from another table. I have displayed it in the template with include ('view'), but now that I pass between subpages, it throws an error with an unknown variable. Classic :/

rollers.blade.php:

<!-- Calendar's Roll (right) -->
       @foreach($calendars as $calendar)
       <li><a href="{{ URL::to('calendar') }}"><b>{{ $calendar->header }}</b> <small>- {{ $calendar->date }}</small></a></li>
       @endforeach

RollersController:

 public function index(CalendarRepository $calRepo)
    {
        $current = Carbon::now();
        $calendars = Calendar::has('photos')->with('photos')->where('date','>=',$current)->orderBy('date', 'asc')->take(3)->get();        
        return view('pages.rollers.rollers', compact('calendars'));
    }

template.blade.php

@include('pages.rollers.rollers')

I need do something like global variable? How can I solve this?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.