
Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given
Argument 1 passed to SymfonyComponentHttpFoundationResponse::setContent() must be of the type string or null, object given
We will use programming in this lesson to attempt to solve the "Argument 1 passed to SymfonyComponentHttpFoundationResponse::setContent() must be of the type string or null, object given".
Sometimes you got error Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given because you return object directly instead of passing to view or return in json format.-
Return data to view or in json format instead of return object
$lastUser = DB::table('users')->latest()->first(); //return $lastUser; return response()->json($lastUser); //Or return view('home', compact('lastUser'));
If you are getting error Argument 1 passed to Symfony\Component\HttpFoundation\Response::setContent() must be of the type string or null, object given, just remove return $lastUser from code or just replace code with return view('home', compact('lastUser')); or you can also return by calling return response()->json($lastUser); method. To return response the content should be type of string or null in our case.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- Validation for multiple forms on same page in laravel
- How to add active class to menu item in laravel
- Get today records in Laravel
- How to check relationship is loaded or not in Laravel
- How to run a specific seeder class in laravel
- How to make Copy or Duplicate table row in laravel
- How to print form data in laravel
- The use statement with non-compound name 'DB' has no effect
- Create a record if not exist in laravel
- The use statement with non-compound name 'Auth' has no effect
- First and last item of the array using foreach iteration in laravel blade
- Class 'App\Http\Controllers\User' not found
- How to insert dynamic value to additional column in pivot table in laravel
- Rename Pivot Table in Laravel
- How to get session in blade Laravel ?
- How to check if user has created any post or not in laravel
- How to get all posts which contains comments in laravel
- Convert input array to comma-separated string in laravel controller
- Call to a member function getRelationExistenceQuery() on array in Laravel
- How to validate website url in laravel using validaiton
- Argument 1 passed to Illuminate\Database\Query\Builder::cleanBindings() must be of the type array, null given
- How to pass link from controller to view in laravel on ajax call
- Conditional validation in laravel
- Add [name] to fillable property to allow mass assignment on [App\Models\Project]
- How to Access Array in blade laravel