Home » Php » Laravel Eloquent Save Item Error?

Laravel Eloquent Save Item Error?

Posted by: admin November 29, 2017 Leave a comment

Questions:

When I try saving an item’s to my database I get

Method Clients::__toString() must return a string value 

Current code

        $name = Input::get('email');
        $client = Input::get('client');
        $website = Input::get('website');
        $userassign = Input::get('userassign');

        $client = new Clients();
        $client->name = $name;
        $client->client = $client;
        $client->website = $website;
        $client->parent = $userassign;


        $client->save();

Any ideas?

Answers:

You’re redefining $client.

        $name = Input::get('email');
        $clientInput = Input::get('client');
        $website = Input::get('website');
        $userassign = Input::get('userassign');

        $client = new Clients(); 
        $client->name = $name; 
        $client->client = $clientInput; //Here was your problem
        $client->website = $website;
        $client->parent = $userassign;


        $client->save();