hasOne relationship not saving

Posted 9 months ago by Sidirgot

Hello, well i been trying to figure out this issue for the past hour without any luck!!

I have a product table and a Manufacturers table in my db with a hasOne relationship declared like this:

Product Model

public function manufacturers()
      return $this->hasOne('App\Manufacturers');

Manufacturer Model

class Manufacturers extends Model
   public function product()
         return $this->belongsTo('App\Product');

Now i am getting the manufacturer option from a select field i have and the value comes as the manufacturer name and i am trying to save the relationship like this


And i been getting this error

"Type error: Argument 1 passed to Illuminate\Database\Eloquent\Relations\HasOneOrMany::save() must be an instance of Illuminate\Database\Eloquent\Model, string given, called in C:\xampp\htdocs\backend-ecom\app\Http\Controllers\Backend\ProductController.php on line 79

Anyone has any idea, it's been driving me crazy!

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.