Skip to content
Advertisement

How to get data with sorting from controller?

I have this query I want to get data from the database with alphabetically sorting

    $states = State::where('status', 1)->sortBy('name')->get();

Advertisement

Answer

Which framework are you using If laravel then write below syntax

$states = State::where('status', 1)->orderBy('name', 'ASC')->get();
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement