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.

Reply to

Use Markdown with GitHub-flavored code blocks.