I building a helper in laravel to return a single field from eloquent.
class Helper {
public static function getAddress($id) {
//intval($id);
$result = DB::table('tableaddress')
->where('id',$id)
->pluck('address');
//dd($result);
return $result;
}
}
In the view i'm calling it via {!! Helper::getAddress(112233) !!}
but getting an error of Array to string conversion
.
Here is if the result of dd
How do I get the address to return a string. Thanks
You need to get first result from an array, so use this:
->pluck('address')[0];