Open natsu90 opened 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;
$category->belongs_to = null;
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.
etrepat/baum
belongs_to
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,
create function in my controller,
update: no error when I set
$category->belongs_to = null;