I have method store:
public function store(CreateProductRequest $request){
$product = new Product($request->all());
Auth::user()->products()->save($product);
Session::flash('status3', 'Produkt został dodany poprawnie');
return redirect('warehouse');
}
In this method I used Auth::user to add the name of the user who added a new record to the database.
I want to do the same in the method update:
public function update($id, CreateProductRequest $request){
$product = Product::find($id);
$products = new Product($request->all());
Auth::user()->products()->update($products);
Session::flash('status4', 'Produkt został zaktualizowany poprawnie');
return redirect('warehouse');
}
and method products in model User:
public function products(){
return $this->hasMany('App\Product');
}
Laravel returned:
Type error: Argument 1 passed to Illuminate\Database\Eloquent\Relations\HasOneOrMany::update() must be of the type array, object given, called in ...