skip to Main Content

I am new in laravel, I want to convert SQL result to string in laravel, below is what I did even though I dont get the result a desire, that is returning client_name as a string.

$client_name = DB::table('utility_data')
    ->select('client_name')
    ->where('identity_number', '=', $identity_number)
    ->first();

dd($client_name);

Above script select client name from the database, I want to convert that value to a string, any idea on how to achieve this? This is what I get as result,
I want to extract the value "Nosi Chefane":

{#303 ▼
  +"client_name": "Nosi Chefane"
}

2

Answers


  1. If you printing it from a controller, just use return $client_name and you should see the data as a JSON object

    Login or Signup to reply.
  2. If you’d like to return just the name itself, you’d have to access it within the object returned in the query:

    dd($client_name->client_name);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search