How do I get the second last record of a table in laravel

MonaMuhr

I want the second last record from my table and search already and I tried this:

$news2 = News::orderBy('created_at', 'desc')->skip(1)->take(1)->get();

but nothing works.

I get this error:

Property [datum] does not exist on this collection instance. (View: C:\xampp\htdocs\j4ylara\resources\views\user\start.blade.php)

If I want the last one everything works it perfectly.

$news1 = News::all()->last();

and my view is the same

<div class="col-12 col-md-6 news">


    <div class="news-content">
                    <div class="date"><i class="far fa-calendar-alt"></i> {{ $news1->datum }}</div>
                    <h4 class="news-title">{{ $news1->newstitel }}</h4>
                    <p class="news-text">{{ $news1->newsbeschreibung }}</p>
                    <a href="#" class="btn btn-primary">
                        mehr lesen &raquo;
                    </a>
                </div>
            </div>
        </div>
        <div class="row no-gutters news-wrapper">
            <div class="col-12 col-md-6 news-image">
                <img class="img-fluid" src="https://picsum.photos/385/370/?random">
            </div>
            <div class="col-12 col-md-6 news">
                <div class="news-content">
                    <div class="date"><i class="far fa-calendar-alt"></i>{{ $news2->datum }}</div>
                    <h4 class="news-title">{{ $news2->newstitel }}</h4>
                    <p class="news-text">{{ $news2->newsbeschreibung }}</p>
                    <a href="#" class="btn btn-primary">
                        mehr lesen &raquo;
                    </a>
                </div>
            </div>
        </div>
MonaMuhr

I GET IIIIIIIIIIIT AHHHHHHHHHH :)

$row = News::count();
        $newsid = $row -2;
        $news1 = News::all()->last();
        $news2 = News::orderBy('created_at', 'desc')->skip($newsid)->take($newsid)->first();
        return view('user/start', compact('news1', 'news2', 'newsid'));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I get the last record in a table with a where clause using Laravel?

From Dev

How do I get the last and second last inserted data of a certain user in table in mysql?

From Dev

How to get second last record in a queryset in Django?

From Dev

How do I get the last record from sql server?

From Dev

Laravel Eloquent how to get the second or third record?

From Dev

how to get last inserted record in a table?

From Dev

Get all record from one table plus the relative last record of a second table

From Dev

How do i find the second to last symbol?

From Dev

Django- How to get second last record in a queryset?

From Dev

how to get second last record from driverid Sql server

From Dev

How to get the next record in a Table using Laravel?

From Dev

How do I get last record from a mysql column through php where several other query is running

From Dev

Get second last row of a table

From Dev

Get last record in mysql table

From Dev

How to get only the second duplicated record in laravel 5.5?

From Dev

How to get the last record from Ms Access table

From Dev

How to get last 5 mins record from SQL database table?

From Dev

How to get the last record from Ms Access table

From Dev

How to get last 5 mins record from SQL database table?

From Dev

How to get Last and Secondlast Record from mysql table

From Dev

How do I get a tenth part of a second?

From Dev

Aerospike: how do I get record key?

From Dev

How do I extract the second to last occurrence of a string in MySQL?

From Dev

How do I index from the second position to the last to the first?

From Dev

How can i get the last inserted record in Android?

From Dev

How I could get the last value per record in awk?

From Dev

How do I get rid of the last comma?

From Dev

How do I get the last character with jquery

From Dev

How to get first record and last record in a date

Related Related

  1. 1

    How do I get the last record in a table with a where clause using Laravel?

  2. 2

    How do I get the last and second last inserted data of a certain user in table in mysql?

  3. 3

    How to get second last record in a queryset in Django?

  4. 4

    How do I get the last record from sql server?

  5. 5

    Laravel Eloquent how to get the second or third record?

  6. 6

    how to get last inserted record in a table?

  7. 7

    Get all record from one table plus the relative last record of a second table

  8. 8

    How do i find the second to last symbol?

  9. 9

    Django- How to get second last record in a queryset?

  10. 10

    how to get second last record from driverid Sql server

  11. 11

    How to get the next record in a Table using Laravel?

  12. 12

    How do I get last record from a mysql column through php where several other query is running

  13. 13

    Get second last row of a table

  14. 14

    Get last record in mysql table

  15. 15

    How to get only the second duplicated record in laravel 5.5?

  16. 16

    How to get the last record from Ms Access table

  17. 17

    How to get last 5 mins record from SQL database table?

  18. 18

    How to get the last record from Ms Access table

  19. 19

    How to get last 5 mins record from SQL database table?

  20. 20

    How to get Last and Secondlast Record from mysql table

  21. 21

    How do I get a tenth part of a second?

  22. 22

    Aerospike: how do I get record key?

  23. 23

    How do I extract the second to last occurrence of a string in MySQL?

  24. 24

    How do I index from the second position to the last to the first?

  25. 25

    How can i get the last inserted record in Android?

  26. 26

    How I could get the last value per record in awk?

  27. 27

    How do I get rid of the last comma?

  28. 28

    How do I get the last character with jquery

  29. 29

    How to get first record and last record in a date

HotTag

Archive