Skip to content
Advertisement

How can I get data using if else in laravel elequent

Suppose I have a Salary model contains column of month and year I want to fetch data like

    Salary::where((year==date('Y') && month<date('m')) || year<date('Y'))->get()

How can I get in laravel elequent?

Advertisement

Answer

Try this

Salary::where([
        ['year', '=', date('Y')],
        ['month', '<', date('m')]
    ])
    ->orWhere('year', '<', date('Y'))
    ->get()
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement