ErrorException (E_NOTICE) Undefined index: month

Posted 1 year ago by imposition

Hi guys! I'm getting the tittle error with the following code:

BlogController:

    public function index()
    {
      
        
        $blogs = Blog::latest()
        ->filter(request(['month', 'year']))
        ->get();
        




        $archives = Blog::selectRaw('year(created_at) year, monthname(created_at) month, count(*) published')
            ->groupBy('year', 'month')
            ->orderByRaw('min(created_at) desc')
            ->get()
            ->toArray();






        return view('welcome', compact('blogs', 'archives'));
    }

Blog model:

        public function scopeFilter($query, $filters)
        {
            
            
        if ($month = $filters['month']) {

            $query->whereMonth('created_at', Carbon::parse($month)->month);
        }
        
        if ($year = $filters['year']) {

            $query->whereYear('created_at', $year);
        }

What should i do ?

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

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.