public function sell()
 {
     $categories = Category::lists('name', 'id');
     if (Request::isMethod('post')) {
         $rules = ['name' => 'required', 'description' => 'required', 'category' => 'required', 'file1' => 'required|mimes:jpeg,bmp,png', 'file2' => 'required|mimes:jpeg,bmp,png'];
         $validator = Validator::make(Input::all(), $rules);
         if ($validator->fails()) {
             $messages = $validator->messages();
             return Redirect::to('piac/eladok')->withErrors($messages)->withInput();
         } else {
             $adv = new Advertisement();
             $adv->name = Input::get('name');
             $adv->description = Input::get('description');
             $adv->category_id = Input::get('category');
             $adv->visible_from = Input::get('visible_from');
             $adv->visible_until = Input::get('visible_until');
             $adv->user_id = Auth::id();
             $adv->seo_url = Helper::lake_directory(Input::get('name'));
             $adv->save();
             if (Input::hasFile('file1') && Input::hasFile('file2')) {
                 $files = [];
                 $files[] = Input::file('file1');
                 $files[] = Input::file('file2');
                 $files[] = Input::file('file3');
                 $files[] = Input::file('file4');
                 $files[] = Input::file('file5');
                 foreach ($files as $key => $file) {
                     $directory = 'USER_' . Auth::id() . '/' . $adv->id;
                     $tmpFilePath = $_SERVER['DOCUMENT_ROOT'] . '/images/advertisements/' . $directory . '/';
                     if ($file) {
                         $tmpFileName = time() . '-' . $file->getClientOriginalName();
                         $file->move($tmpFilePath, $tmpFileName);
                         $advImg = new AdvertisementImage();
                         $advImg->advertisement_id = $adv->id;
                         $advImg->url = $directory . '/' . $tmpFileName;
                         $advImg->save();
                     }
                 }
             }
             Session::flash('message', 'Köszönjük!.Egyik adminisztrátorunk engedélyezni fogja hírdetésedet a következő 30 percben.');
             return Redirect::to('/');
         }
     }
     return view('market.sell', ['categories' => $categories]);
 }
Esempio n. 2
0
 public function upload()
 {
     if (Input::hasFile('file')) {
         $allFiles = Input::file('file');
         $directory = Helper::lake_directory(Input::get('lakeName'));
         $tmpFilePath = '/lakes/' . $directory;
         if (empty($directory) || strlen($directory) < 5) {
             return response()->json(false, 501);
         }
         if ($allFiles) {
             foreach ($allFiles as $file) {
                 $tmpFileName = time() . '-' . $file->getClientOriginalName();
                 $file = $file->move(Config::get('constants.IMAGES_ABSOLUTE_URL') . '' . $tmpFilePath, $tmpFileName);
                 // $path = $tmpFilePath . $tmpFileName;
             }
             return response()->json('OK', 200);
         } else {
             return response()->json(false, 501);
         }
     } else {
         return response()->json(false, 501);
     }
 }
Esempio n. 3
0
 public function create()
 {
     $fish = new Fish();
     if (Request::isMethod('post')) {
         $rules = array('name_ro' => 'required', 'name_hu' => 'required', 'description' => 'required', 'url' => 'required');
         $validator = Validator::make(Input::all(), $rules);
         // process the login
         if ($validator->fails()) {
             return Redirect::to('admin/fish/create/')->withErrors($validator)->withInput();
         } else {
             if (empty(Input::get('fish_seo_url'))) {
                 $seo_url = Helper::seo_url(Input::get('name_ro'));
             } else {
                 $seo_url = $Input::get('fish_seo_url');
             }
             // store
             $fish->name_ro = Input::get('name_ro');
             $fish->name_hu = Input::get('name_hu');
             $fish->url = Input::get('url');
             $fish->description = Input::get('description');
             $fish->enabled = Input::get('enabled') == 'on' ? 1 : 0;
             $fish->save();
             $directory = Helper::lake_directory(Input::get('name_ro'));
             $path = Config::get('constants.IMAGES_ABSOLUTE_URL') . '/fish/' . $directory . '/';
             $images = [];
             if (file_exists($path)) {
                 //Read iamges from file
                 if ($handle = opendir($path)) {
                     while (false !== ($file = readdir($handle))) {
                         if (strpos(strtolower($file), ".jpg") || strpos(strtolower($file), ".gif") || strpos(strtolower($file), ".png")) {
                             $images[] = $file;
                         }
                     }
                     closedir($handle);
                 }
                 $imageIds = [];
                 $fishID = $fish->id;
                 if (!empty($images)) {
                     foreach ($images as $key => $img) {
                         $fishImg = new FishImage();
                         $fishImg->url = $directory . '/' . $img;
                         $fishImg->enabled = 1;
                         $fishImg->uploaded = date("Y-m-d H:i:s");
                         $fishImg->save();
                     }
                 }
             }
             // redirect
             Session::flash('message', 'New fish has been created successfully');
             return Redirect::to('/admin/fishs');
         }
     }
     return view('admin.fish.create')->with(['fish' => $fish]);
 }