How to get the last inserted record Id on Codeigniter?

The Codeigniter is the Lightweight fast and object-oriented PHP Framework. Sometimes we need the last inserted record Id for inserting the related data into another table. When we are working on product module at that time we insert product data to the database and also we need to insert product-related data like product attribute insert to the database we need the product id for stored attribute data.

Continue reading How to get the last inserted record Id on Codeigniter?

Laravel 5.5 get last inserted record Id

Today, We are learning how we get the last inserted record Id on Laravel. Many times we need the last inserted record Id for the further operation. Laravel provides many ways to fire record insert query. Let’s see the different way to get the last inserted record Id using Laravel method.

Continue reading Laravel 5.5 get last inserted record Id

Laravel find the records between two different numbers in MySQL

Laravel how to find the records between two different number. Like many times we need to find the product price greater than 15 and lower than 525. So how can write a query in Laravel? So it’s too easy to find the record between two number. Let’s see how to create a between condition on laravel eloquent.

<?php
$product = Product::where('status', '=', 1)
    ->whereBetween('price', [15, 525])
    ->get();

Or else you can use the ‘>’ and ‘<‘ condition for the getting same record instead of using ‘whereBetween’. let’s see how we can get the product price between greater than 15 and lower than 525.

<?php
$product = Product::where('status', '=', 1)
    ->where('price','>=',15)
    ->where('price','<=',525)
    ->get();

you can use both of the conditions for getting the product price between 15 to 525.

If you face any issue after using this query please write the comment below.

Laravel find if number is between two different fields in a MySQL Database

Laravel find the number is between two different fields. Many times we find the record between two dates ‘from’ to ‘to’ date right. But how to find a number of between two fields. So it’s too easy in Laravel. So let’s see how to write `DB RAW` query in Laravel for find number between two fields.

Just used below simple query.

<?php
$itemExits = Availability::whereDate('status','=','1')
    	->whereRaw(\DB::raw(' 25 BETWEEN `from_no` AND `to_no` '));
$result = $itemExits->get();

As per above query, we get to record like greater than ‘from_no’ and lower than ‘to_no’ records from the database.

we can write two separate conditions for the getting same records like below.

<?php
$itemExits = Availability::whereDate('status','=','1')
    	->where('from_no','>=',25)
        ->where('to_no','<=',25);
$result = $itemExits->get();

We get the same result as above query both query return the same result.

If you face any issue after using the above query please write the comment below.