Siti Rahmah
Siti Rahmah

Reputation: 267

I want to take the first character of use LEFT on laravel `

Maybe anyone can help me?

This is my controller.

$takegolongan = Pekerjaan::select ('LEFT('golongan_jabatan', 1)')->where('cno', '00001222')->get();

echo $takegolongan;

This is the data that I want to take :

enter image description here

output on the screen (error):

enter image description here

Upvotes: 1

Views: 2052

Answers (2)

Ramesh Mhetre
Ramesh Mhetre

Reputation: 404

You should add single quote inside the double quote or you should use backslash, I can only see the issue of quotes. Like:

    $takegolongan = Pekerjaan::select ("LEFT('golongan_jabatan', 1)")->where('cno', '00001222')->get();

Upvotes: 1

Jin.C
Jin.C

Reputation: 121

You can use DB::raw() like this:

use DB;

$takegolongan = Pekerjaan::select(DB::raw('LEFT(`golongan_jabatan`, 1)'))
    ->where('cno', '00001222')
    ->get();

Upvotes: 1

Related Questions