title = $request->title; $event->description = $request->description; $event->location = $request->location; $event->topic = $request->topic; $event->goal = $request->goal; $event->hosted_by = $request->hosted_by; $event->date = $request->date; if ($request->hasFile('image')) { $imageName = rand(999, 111) . time() . '.' . $request->image->extension(); $request->image->move(public_path('uploads/events'), $imageName); $event->image = $imageName; } if ($event->save()) { $this->notice::success('Data Saved'); return redirect()->route('event.index'); } else { $this->notice::error('Please try again'); return redirect()->back()->withInput(); } } catch (Exception $e) { dd($e); $this->notice::error('Please try again'); return redirect()->back()->withInput(); } } /** * Display the specified resource. */ public function show(Event $event) { // } /** * Show the form for editing the specified resource. */ public function edit($id) { $event = Event::findOrFail($id); return view('backend.event.edit', compact('event')); } /** * Update the specified resource in storage. */ public function update(Request $request, $id) { try { $event = Event::findOrFail($id); $event->title = $request->title; $event->description = $request->description; $event->location = $request->location; $event->topic = $request->topic; $event->goal = $request->goal; $event->hosted_by = $request->hosted_by; $event->date = $request->date; if ($request->hasFile('image')) { $imageName = rand(999, 111) . time() . '.' . $request->image->extension(); $request->image->move(public_path('uploads/events'), $imageName); $event->image = $imageName; } if ($event->save()) { $this->notice::success('Data Saved'); return redirect()->route('event.index'); } else { $this->notice::error('Please try again'); return redirect()->back()->withInput(); } } catch (Exception $e) { dd($e); $this->notice::error('Please try again'); return redirect()->back()->withInput(); } } /** * Remove the specified resource from storage. */ public function destroy($id) { $data = Event::findOrFail($id); if ($data->delete()) { $this->notice::error('Data Deleted!'); return redirect()->back(); } } }