/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function track(Batch $batch, Request $request) { $this->validate($request, ['towns_id' => 'required|integer', 'status_id' => 'required|integer', 'message' => '']); if ($batch->isDelivered()) { alert()->warning('The batch has been delivered already.', 'Oops'); return redirect('batch/' . $batch->id); } $batch->update(['status_id' => $request->get('status_id')]); foreach ($batch->parcel()->get() as $t) { $t->parcel->update(['status_id' => $request->get('status_id')]); $t->parcel->track()->create(['towns_id' => $request->get('towns_id'), 'user_id' => auth()->user()->id, 'message' => $request->get('message'), 'status_id' => $request->get('status_id')]); } $batch->track()->create(['town_id' => $request->get('towns_id'), 'user_id' => auth()->user()->id, 'message' => $request->get('message'), 'status_id' => $request->get('status_id')]); // Fire email event at this stage event(new ActivityLog(auth()->user()->username . ' updated the track details for the batch ' . $batch->description . ' with the code ' . $batch->code . ' successfully.')); alert()->success('Batch track details updated successfully', 'Success'); return redirect('batch/' . $batch->id); }