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) { $course = Course::get(); $event = Event::findOrFail(encryptor('decrypt', $id)); return view('backend.event.edit', compact('course', 'event')); } /** * Update the specified resource in storage. */ public function update(Request $request, $id) { try { $event = Event::findOrFail(encryptor('decrypt', $id)); $event->title = $request->lessonTitle; $event->course_id = $request->courseId; $event->description = $request->lessonDescription; $event->notes = $request->lessonNotes; 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(encryptor('decrypt', $id)); if ($data->delete()) { $this->notice::error('Data Deleted!'); return redirect()->back(); } } }