10-Apr-2023
.
Admin
Hi Guys,
In this example,I will learn you how to select custom column with value in laravel query.you can easy and simply how to select custom column with value in laravel query.
so here, i will give you very simple example for adding custom column with value.
Example:
<?php
namespace App\Http\Controllers;
use App\Models\User;
use DB;
class UserController extends Controller
{
/**
* Write code on Method
*
* @return response()
*/
public function index()
{
$users = User::select([
"id",
"name",
DB::raw("'Admin' as type"),
DB::raw("1 as active")
])->get();
dd($users->toArray());
}
}
Output:
Array
(
[0] => Array
(
[id] => 1
[name] => Keval
[type] => Admin
[active] => 1
)
[1] => Array
(
[id] => 2
[name] => Mehul
[type] => Admin
[active] => 1
)
)
It will help you...
#Laravel 8
#Laravel 7
#Laravel
#Laravel 6