1

sorry for newbie question. I want to get from table specific columns, order them by date and extract only 150 rows. I tried a lot of combinations. But i dont get the point how should it work:

public function get()
    {
        Excel::create('Bids-' . date("Y/m/d"), function($excel) {
            $excel->sheet('Favourites', function($sheet) {
                $comments = Comment::select('auction_name','bid','lot_date','company', 'model_name_en', 'body','grade_en', 'mileage_num', 'model_year_en', 'start_price_en')->sortBy("lot_date", 'desc')->take(150)->get();
                $sheet->fromModel($comments);
            });
        })->download('xls');
    }

Please, can some one explain me what im doing wrong, why sortBy dont want to work?

2 Answers 2

2
$comments = Comment::select('auction_name','bid','lot_date','company', 'model_name_en', 'body','grade_en', 'mileage_num', 'model_year_en', 'start_price_en')->orderBy("lot_date", 'desc')->take(150)->get();

notice usage of orderBy() instead of sortBy().

Sign up to request clarification or add additional context in comments.

2 Comments

Please provide proper formatting and explain your answer
it did work actually, the problem was in that i need to use orderBy in stead of sortBy
0

Actually i find a solution, but i still hardly get it, why it didn't work in before.

This is the solution:

Excel::create('Bids-' . date("Y/m/d"), function($excel) {
            $excel->sheet('Favourites', function($sheet) {

                $comments = Comment::select('auction_name','bid','lot_date','company', 'model_name_en', 'body','grade_en', 'mileage_num', 'model_year_en', 'start_price_en')->take(150)->get();
                $result = $comments->sortByDesc('lot_date');
                $sheet->fromModel($result);
            });
        })->download('xls');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.