ErrorException (E_NOTICE) Undefined index: month

Posted 1 year ago by imposition

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


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

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

        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.