コード例 #1
0
ファイル: FileController.php プロジェクト: matthiku/cSpot
 /**
  * FILES/IMAGES HANDLING
  *
  */
 public function index(Request $request)
 {
     $heading = 'List All Files and Images';
     $querystringArray = $request->input();
     # does session contains a filter value?
     if ($request->has('bycategory')) {
         // get only FILES with this specific file_category id
         $file_category = FileCategory::find($request->input('bycategory'));
         if ($file_category) {
             $heading = 'Show Files of type "' . $file_category->name . '"';
             // get all files of this category
             $files = $file_category->files()->paginate(18)->appends($querystringArray);
         }
     }
     if ($request->has('newest')) {
         $heading = 'Recently added files';
         $files = File::orderBy('id', 'desc')->paginate(18);
     }
     // default: show all files
     if (!isset($files)) {
         $files = File::paginate(18);
     }
     // URL contains ...?item_id=xxx (needed in order to add an existing file to an item)
     $item_id = 0;
     if ($request->has('item_id')) {
         $item_id = $request->item_id;
         $heading = 'Select a file for the Plan Item';
     }
     // get list of file categories
     $file_categories = FileCategory::get();
     // for pagination, always append the original query string
     $files = $files->appends($querystringArray);
     return view('admin.files', ['files' => $files, 'item_id' => $item_id, 'heading' => $heading, 'file_categories' => $file_categories]);
 }
コード例 #2
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     // default values cannot be deleted
     if ($id < 1) {
         $message = 'Error! The basic File Categories (IDs 0 and 1) cannot be deleted!';
         return \Redirect::route($this->view_idx)->with(['status' => $message]);
     }
     // find a single resource by ID
     $output = FileCategory::find($id);
     if ($output) {
         $output->delete();
         $message = 'File Category with id "' . $id . '" deleted.';
         return \Redirect::route($this->view_idx)->with(['status' => $message]);
     }
     //
     $message = 'Error! File Category with ID "' . $id . '" not found';
     return \Redirect::route($this->view_idx)->with(['status' => $message]);
 }