/**
  * save gallery in the database
  */
 public function saveGallery(Request $request)
 {
     // POST request requires the 'Request' object as parameter
     // validate the request throught the validation rules
     // 1st argument: the request (specifically, all request)
     // 2nd argument is the validation rules array based on the name of the user input and piped with other rules
     // 3rd argument is optionally used to override the default error message that already comes with Validator
     $validator = Validator::make($request->all(), ['gallery_name' => 'required|min:3']);
     // take action if validation fails
     // this will redirect user back to the gallery list but will include the errors and the user's previous input
     // use the $errors variable on the html page so that you can output using a foreach loop
     // use the html <input value="{{ old('gallery_name') }}"> to catch the previous input for display
     if ($validator->fails()) {
         return redirect('gallery/list')->withErrors($validator)->withInput();
         // include user's previous input
     }
     // request validation has passed the validation rules at this point, now proceed with saving gallery
     $gallery = new Gallery();
     // save a new gallery
     $gallery->name = $request->input('gallery_name');
     // 'gallery_name' is the name of the html input field
     $gallery->created_by = 1;
     // hard coded for now
     $gallery->published = 1;
     // hard coded for now
     $gallery->save();
     // save the user's input into the database
     return redirect()->back();
     // redirect user back to the previous page (page where the user saves a gallery)
 }
 /**
  * Helper untuk melakukan Add new Data ke dalam database
  * 
  */
 private function addData()
 {
     $data = new Gallery();
     $file = Input::file('gallery');
     $image_name = time() . "-gallery-" . $file->getClientOriginalName();
     $file->move(public_path() . '/upload', $image_name);
     $data->image = $image_name;
     $data->save();
     return true;
 }
 public function saveGallery(Request $request)
 {
     //validate the request through the validation rules
     $validator = Validator::make($request->all(), ['gallery_name' => 'required|min:3']);
     // if Validator fails
     if ($validator->fails()) {
         return redirect('gallery/list')->withErrors($validator)->withInput();
     }
     $gallery = new Gallery();
     // save a new gallery
     $gallery->name = $request->input('gallery_name');
     $gallery->created_by = Auth::user()->id;
     $gallery->published = 1;
     $gallery->save();
     flash()->success('You have successfully added your gallery');
     return redirect()->back();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['image' => 'required']);
     if ($validator->fails()) {
         return redirect('galery')->withErrors($validator)->withInput();
     }
     $gallery_name = $request->input('gallery_name');
     $files = $request->file('myfile');
     //$captions     =   $request->input('caption');
     if (empty($gallery_name)) {
         //if no gallery is named, then
         $gallery_name = 'Timeline Photos';
     }
     $gallery = new Gallery();
     $gallery->name = $gallery_name;
     $gallery->save();
     //save gallery for once in gallery table
     //for image counting, files is in array so used array_filter($files)
     for ($i = 0; $i < count(array_filter($files)); $i++) {
         $filename = uniqid() . $files[$i]->getClientOriginalName();
         if (!file_exists('gallery/images')) {
             //create file
             mkdir('gallery/images', 077, true);
         }
         $files[$i]->move('gallery/images', $filename);
         //upload image to folder
         $image = new ImageModel();
         //$image->caption     =  $captions[$i];
         $image->file_name = $filename;
         $image->file_size = $files[$i]->getClientSize();
         $image->file_mime = $files[$i]->getClientMimeType();
         $image->file_path = 'gallery/images/' . $filename;
         $gallery->image()->save($image);
     }
     //saving images to image table with eloquent relationship
     //gallery id is passed automatically to image table
     //Session::flash('flash_message','Image succesfully Updated');
     //return redirect('/galery');
 }
 /**
  * Действие-обработчик запроса на сохранение фотографии.
  *
  * @param StoreGalleriesRequest $request
  * @param SavesImages $imageSaver
  * @return \Illuminate\Http\RedirectResponse
  * @throws \App\Services\Exception
  */
 public function postCreate(StoreGalleriesRequest $request, SavesImages $imageSaver)
 {
     $photo = new Gallery();
     $photo->title = trim($request->title);
     $photo->file_name = $imageSaver->save('file_name', 'galleries', 973);
     $photo->company_id = Company::whereShortTitle($request->company)->first(['id'])->id;
     $photo->save();
     return redirect('admin/galleries/edit/' . $photo->id . '?company=' . $request->company)->with('success', 'Сертификат успешно сохранен.');
 }