Scoping Of Variable

Posted 3 months ago by kshitizmittal
if(date('m')>=4){
            $start_year = date('Y');
            $end_year = date('Y')+1;
        } else {
            $start_year = date('Y')-1;
            $end_year = date('Y');
        }
        
        $taxsavings = Taxsaving::with([
            'assignTaxSaving' => function($query) {
                $query->where(['emp_id'=>Auth::user()->emp_id,'start_year'=>$start_year,'end_year'=>$end_year])->where();    
            },
        ])->get();

Facing Error :- "Undefined variable: start_year"

Please help to resolve this.

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