/**
  * Store a new cost log associated with material from form request
  *
  * @param Request $request
  * @param Material $material
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function store_cost_log(Request $request, Material $material)
 {
     $this->authorize('edit_material');
     $this->validate($request, ['mat_cost_cost_kg' => 'required|numeric|min:0', 'mat_cost_date' => 'required|date']);
     $material->costLogs()->save(MaterialCostLog::create($request->all()));
     flash()->success('Material Cost Saved', 'A new cost log has been added to the material');
     //
     return redirect()->action('MaterialController@index');
 }
 /**
  * Overwrite the parent boot method
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     MaterialCostLog::creating(function ($materialCostLog) {
         $materialCostLog->mat_cost_added_user_id_fk = \Auth::user()->id;
         $materialCostLog->mat_cost_modified_user_id_fk = \Auth::user()->id;
     });
     MaterialCostLog::updating(function ($materialCostLog) {
         $materialCostLog->mat_cost_modified_user_id_fk = \Auth::user()->id;
     });
 }