Exemplo n.º 1
0
 public function index(Request $request)
 {
     $q = $request->q;
     $announcements = Announcement::where('user_id', Auth::user()->id)->where(function ($query) use($q) {
         $query->where('title', 'LIKE', '%' . $q . '%');
         $query->orWhere('content', 'LIKE', '%' . $q . '%');
     })->orderBy('created_at', 'DESC')->paginate(7);
     $page_title = $request->has('q') ? 'Pencarian ' . $q : 'Pengumuman';
     return view('admin.announcements.index', compact('q', 'announcements', 'page_title'));
 }
Exemplo n.º 2
0
 public function index()
 {
     if (Auth::check()) {
         if (Auth::user()->hasRole('staff')) {
             return redirect()->intended('/lms-admin');
         } else {
             return redirect()->intended('/home');
         }
     }
     $page_title = 'Login';
     $announcements = Announcement::where('status', 'info')->limit(3)->get();
     return view('auth.login', compact('page_title', 'announcements'));
 }
Exemplo n.º 3
0
 public function index()
 {
     $announcements = Announcement::where('date', '>=', date("Y-m-d"))->orderBy('date', 'asc')->get();
     return view('announcements.index', ['announcements' => $announcements]);
 }
Exemplo n.º 4
0
 public function destroy(Request $request, $id)
 {
     $v = Announcement::find($id);
     if ($v) {
         // retrieve image detail prior to deletion
         $images = DB::table('files')->join('announcement_files', 'files.id', '=', 'announcement_files.file_id')->where('announcement_files.announcement_id', $id)->get();
         $res = Announcement::where("id", $id)->where('user_id', Auth::user()->id)->delete();
         if ($res) {
             // delete also the images from db and local storage
             if (count($images) > 0) {
                 foreach ($images as $image) {
                     try {
                         $imgFile = File::find($image->file_id);
                         if ($imgFile) {
                             $imgFile->delete();
                             \Illuminate\Support\Facades\File::delete(MyHelper::getImageFromStorage($id, $imgFile->new_filename));
                         }
                     } catch (\Exception $e) {
                         Log::info($e->getMessage());
                     }
                 }
             }
             $request->session()->flash("notif", "Announcement successfully deleted");
             return ['error' => false];
         } else {
             return ['error' => true, 'message' => 'Failed to delete announcement!'];
         }
     } else {
         $request->session()->flash("notif", "announcement not available!");
         return ['error' => true];
     }
 }