// Sort posts by creation date in ascending order $posts = DB::table('posts')->orderBy('created_at', 'asc')->get(); // Sort users by name in descending order $users = DB::table('users')->orderBy('name', 'desc')->get();
// Sort movies by release date in ascending order $statement = $pdo->prepare('SELECT * FROM movies ORDER BY release_date ASC'); $statement->execute(); $movies = $statement->fetchAll();In this example, we are using the PDO library to sort the "movies" table by release date in ascending order. We prepare a query using the "prepare()" method, execute it using the "execute()" method, and fetch the results using the "fetchAll()" method.