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();