Search code examples
phplaravellaravel-5laravel-5.3

Add element changes in laravel in separate table?


I have a classic create() function to create elements, but changes I wish to save in a separate table, like history. There is table: element_changes and also model created named ElementChange, but in my ElementController, how can I tell to save it in a separate table?

Classic create function:

public function create(Request $request) 
    $item = new Item();
    $item->fill($request->old());
    return view('items.create', compact('item'));
}

Solution

  • You need to tell your model to create the new item

    $item->fill($request-old())->create();