How To Pass Optional Argument Latest() In Laravel

April 30, 2023 | Category : Other

Hello Friends,Hi,
In this tutorial, you will discover laravel latest column. let’s discuss about how to pass optional argument latest() in laravel. This article will give you a simple example of laravel order by column value. This post will give you a simple example of laravel order by latest date. Let's see below example laravel order by date format.

We are normally used latest()

eloquent function to getting latest data with created_at default column. but if you need with another column like published_at or something then how you can do this.

I will show you simple example to pass an optional column with latest() query builder method. so, let's see the simple example:

Controller Code:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Models\Post;

class PostController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index(Request $request)

{

$posts = Post::latest('published_at')->get();

return view('posts', compact('posts'));

}

}

I hope it can help you...