laravel

How to use addSelect() Eloquent Method in Laravel

How-to-use-addSelect()-Eloquent-Method-in-Laravel.png

How to use addSelect() Eloquent Method in Laravel, in this article we will step by step guide to the use of addSelect() method. It is useful when we want to select a column of table with multiple where using.

It is a query builder.

How to use addSelect() Eloquent Method in Laravel

<?php  
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Category;
use DB;
  
class PostController extends Controller
{
    public function index()
    {
        $cate = Category::select("id", "title")
                        ->addSelect("slug")
                        ->addSelect(DB::raw('1 as number'))
                        ->take(10)
                        ->get();
 
        return cate;
    }
}



About author

IMG_8897.png

Muhammad Zubair

My name is Muhammad Zubair. I'm a full-stack developer. I'm a owner of theskillstock.com. I love to write tutorials of PHP, Laravel, Html & css, Javascript, Java and much more with examples.


Comments

No Comments Yet.



Leave a Reply