user image

Joseph Morgan
Published in : 2022-02-04

Response::setContent(): Argument #1 ($content) must be of type


Hello everyone,
I am trying to use with('owner') to get the owner of the record in the DB but I am getting this error “Response::setContent(): Argument #1 ($content) must be of type”

Symfony\Component\HttpFoundation\Response::setContent(): Argument #1 ($content) must be of type ?string, Illuminate\Database\Eloquent\Builder given, called in /Users/Joseph/Desktop/Github/project/vendor/laravel/framework/src/Illuminate/Http/Response.php on line 72

The model code is 


namespace App;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class submit_records extends Model{
    use HasFactory;
    protected $fillable = ['id', 'users', 'type', 'notes'];
    public function owner(){
        return $this->hasOne('App\users', 'id', 'users');

& the function of the controller is 

    public function earnings_manage_discussion($id){
        $data = submit_records::find($id)->with('owner');
        return $data;

Any help! please!


Mohamed Atef Date : 2022-02-04

Best answers


Best answers


You are using a one to one relation (using hasOne()) and this need you to get only one record from the model so you need to add ->first(); at the end of the line of the query and it will be working fine
You can change hasOne() to hasMany() and it should work
OR Better way
You can use only the query in the controller like 

    public function earnings_manage_discussion($id){
        $data = submit_records::find($id);
        return view('post.single', [ 'data' => $data ]);

and then in the blade file, you can use the relation without no problem like


Good luck 

Joseph Morgan Date : 2022-02-04

Thank you Mohamed, That's it

Leave a comment

Join us

Join our community and get the chance to solve your code issues & share your opinion with us

Sign up Now

Related posts

laravel installation error with composer install
Publish date: 2022-02-23 | Comments: 2
Undefined Variable problem on Laravel 9.x
Publish date: 2022-03-06 | Comments: 3
Method Illuminate\Auth\RequestGuard::attempt does not exist.
Publish date: 2022-02-18 | Comments: 2
Laravel redirect to the last location after login
Publish date: 2022-02-21 | Comments: 1
Laravel install passport have access denied error
Publish date: 2022-02-23 | Comments: 4