Skip to content
Advertisement

Why does using vsprintf instead of sprintf to format a query string to pass to Laravel’s DB::select cause the return of a non-object?

I am having trouble when using vsprintf instead of sprintf to format a query string I pass to DB::select. I have narrowed the problem down through elimination. At first I attempted to use sprintf to insert a variable into a string. I used that string as a parameter for DB::select:

JavaScript

The result was fine. I modified the code to allow inserting multiple variables into a string:

JavaScript

The result was fine and identical for both code variants:

JavaScript

I attempted to return a view with the result object passed as a parameter.
return view('post_viewer', ['arr_post' => $rslt_post] );

The result was the following error message:

JavaScript

The referenced line in post_viewer.blade.php is this:
<h4> {{ $arr_post->posted_by }} </h4>.

Why does it claim that a variable verified by dd and print_r as an array object is a “non-object” from which I attempted to access the “property” called “title”?

Advertisement

Answer

no need of sprintf or vsprintf

JavaScript

and fully dynamic

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement