mauricecalhoun / inventory

Inventory Management for Laravel 4 / 5
423 stars 204 forks source link

Missing argument 1 for Illuminate\Database\Eloquent\Model::belongsTo() #38

Open natsu90 opened 9 years ago

natsu90 commented 9 years ago

I'm adding Category but got above error. What did I miss? I've added outlet_id field in database table and my model as follows,

// Category.php
<?php namespace Slurp\Entities;

use Stevebauman\Inventory\Traits\CategoryTrait;
use Baum\Node;

class Category extends Node
{
    use CategoryTrait;

    protected $table = 'categories';

    protected $scoped = ['belongs_to'];

   public function inventories()
   {
        return $this->hasMany('Inventory', 'category_id');
   }

   public function outlet()
   {
        return $this->belongsTo('Outlet', 'outlet_id');
   }
}

create function in my controller,

 ...
 public function createCategory()
 {
       $category = new Category;
       $category->name = $this->request->input('name');
       $category->outlet_id = \Auth::user()->outlet_id;
       if( $category->save())
             return $this->redirector->back()->with('success', 'Added category inventory');
       return $this->redirector->back()->withError('Failed add category inventory');
 }
...

update: no error when I set $category->belongs_to = null;

stevebauman commented 9 years ago

This may be something to do with etrepat/baum for categories. Since belongs_to is scoped, it may need to be set manually to null before saving.