未定义的变量:worklogs_yesterday(查看:/home/riwaj/Desktop/projects/dmt-intern-manager/InternManager/resources/views/home.blade.php)

错误的屏幕截图如下所示。即使在home.blade.php中传递了变量,我仍然得到标题中提到的错误。

未定义的变量:worklogs_yesterday(查看:/home/riwaj/Desktop/projects/dmt-intern-manager/InternManager/resources/views/home.blade.php)

enter image description here

尽管变量worklogs_yesterday显示错误,但该变量已通过其各自的控制器传递。

    public function index()
    {

        $d = new DateTime('first day of this month'); //first date of current month
        $d = $d->format('Y-m-d'); // changing in Y-m-d format

        $e = new DateTime('last day of this month'); //last date of current month
        $e = $e->format('Y-m-d');  // changing in Y-m-d format

        $today = new DateTime();
        $today = $today->format('Y-m-d');

        $yesterday = new DateTime('yesterday');
        $day = $yesterday->format('D');
        $yesterday = $yesterday->format('Y-m-d');
        $friday = date("Y-m-d", strtotime("previous friday"));


        $worklogs = Auth::user()->workLog->take(-7)->reverse();
        $leaves_granted = Leave::where('status', 1)->where('department_id', Auth::user()->department_id)->where('startdate','>', $d)->where('enddate','<', $e)->orderBy('created_at', 'desc')->get();
        $leaves_today = Leave::where('status', 1)->where('department_id', Auth::user()->department_id)->where('startdate','=', $today)->get();

        if($day == 'Sun'||$day == 'Sat'){
        $worklogs_yesterday = Work::where('created_at', 'like', '%' . $friday . '%')->get();
        }else{
        $worklogs_yesterday = Work::where('created_at', 'like', '%' . $yesterday . '%')->get();    
        }




        if(session('role') == 'intern' || session('role') == 'manager'){
            $reset = Auth::user()->isReset;

            if($reset == 0){
                return view('auth.passwords.resetpassword');
            }

        }
        if(session('role') == 'manager'){
            $leaves = Leave::where('status', 0)->where('department_id', Auth::user()->department_id)->orderBy('created_at', 'desc')->get();
            $internrole = Role::where('name', 'intern')->first();
            $intern_list = User::where('department_id', session('department_id'))->get();
            $contracts = User::where('isContractOver','1')->where('department_id', session('department_id'))->get();
            $worklogs = Auth::user()->workLog->take(-7)->reverse();

            $interns = array();

            $contractBool=0;

            if(count($contracts)){
                $contractBool = 1;
            }  

            $check = (Input::get('ContractBool'));
            // dd((Session::get('Bool')));

            if(Session::get('Bool')==1){
                Session::put('Bool',$check);
            }

            // dd($contractBool == 1);
            // dd((Input::get('ContractBool')) );

            if(Session::get('Bool') == null && $contractBool == 1){

                    Session::put('Bool','1');
                    // Input::merge(['ContractBool' => '0']);

                    return view('manager.contract', compact('contracts'));    
            }  

            foreach($intern_list as $intern){
                $role = UserRole::where('user_id', $intern->id)->first();
                if($role->role_id === $internrole->id){
                    array_push($interns, $role);
                }
            }

            return view('home', compact('interns','contracts','worklogs','leaves_granted','leaves_today','worklogs_yesterday'));
        }
        return view('home', compact('worklogs','leaves_granted','leaves_today','worklogs_yesterday'));
    }

我的home.blade.php具有:

<div class="bn-breaking-news" id="newsTicker1">
    <div class="bn-label">UPDATES</div>
    <div class="bn-news">
        <ul>
            <li><a href="#" style="color: red; font-size: large" id="leaves"><b>Leave Report Today</b></a></li>
            @if($leaves_today->isEmpty())
            <li><a href="#">No One is on leave today</a></li>
            @else
            @foreach($leaves_today as $leave_today)
            <li><a href="#"><b>{{$leave_today->users->name}}:</b> {{$leave_today->reason}}</a></li>
            @endforeach
            @endif
            <li><a href="#" style="color: blue; font-size: large" id="leaves"><b>Previous Work Day's Work Report</b></a>
            </li>
            @foreach ($worklogs_yesterday as $worklog_yesterday)
            @if($worklog_yesterday->users->department_id == Auth::user()->department_id )
            <li><a href="#"><b>{{$worklog_yesterday->users->name}}:</b> {{$worklog_yesterday->work_title}}</a></li>
            @endif
            @endforeach

        </ul>
    </div>
    <div class="bn-controls">
        <button><span class="bn-arrow bn-prev"></span></button>
        <button><span class="bn-action"></span></button>
        <button><span class="bn-arrow bn-next"></span></button>
    </div>
</div>

可能是什么原因?

评论