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]); }