Get last 6 month data in laravel eloquent

Get Last 6 Month Data In Laravel Eloquent So much easy…..

get last 6 month data from mysql and laravel eloquent ….

if you have question about laravel get last week records then i will give simple example with laratuto provide all solution for you. This tutorial will give you simple example of get last 6 month data in laravel. if you want to see example of how to get last week data in laravel then you are a right place.

we can get last week records in laravel 6, laravel 7 and laravel 8 application.

Here, i will give you very simple example of how to get last week records in laravel. we will use whereBetween() in this example.

I have one created items table that structure as bellow you can see.Get Last 6 Month Data In Laravel Eloquent

This content database…..

Controller LaraTutoController.php

<?php
  
namespace App\Http\Controllers\Api;
  
use Illuminate\Support\Facades\Http;
use App\Models\Item;
use Carbon\Carbon;
    
class LaraTutoController extends Controller
{
    /**
     * Write code in Method
     *
     * @return response()
     */
    public function index()
    {
         $items = Bookable::select('*')
                        ->whereBetween('created_at', 
                            [Carbon::now()->subMonth(6), Carbon::now()]
                        )
                        ->get();
  
        print_r($items);
    }
}

Output:

Array

(

    [0] => Array

        (

            [id] => 1
            [title] => "East Lessiemouth Fancy Rooms"
            [discription] => "Cum amet sed eveniet magnam. "
            [created_at] => 2021-06-07 17:06:38
            [updated_at] => 2021-06-07 17:06:38

        )

    [1] => Array

        (

            [id] => 2
            [title] => "Ilenemouth Rio Colina"
            [discription] => "Numquam aut consequatur quidem minima at tempora."
            [created_at] => 2021-06-07 17:06:38
            [updated_at] => 2021-06-07 17:06:38

        )

    [2] => Array

        (

            [id] => 3
            [title] => "East Eddie Fancy Rooms"
            [discription] => "Rerum praesentium dolore est distinctio accusamus excepturi."
            [created_at] => 2021-06-07 17:06:38
            [updated_at] => 2021-06-07 17:06:38

        )

)

Leave a Comment