/**
* Store a newly created theme in storage.
*
* @return Response
*/
public function store()
{
$rules = array('name' => 'required', 'description' => 'required', 'thumbnail' => 'required|image', 'version' => '', 'powerful_id' => 'required', 'category_id' => 'required');
$validator = Validator::make($data = Input::except('images'), $rules);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
/**
* Convert list id powerful to json
*/
$data['powerful_id'] = json_encode($data['powerful_id']);
/**
* Upload theme thunbnail
*/
$tb_name = md5(time() . Input::file('thumbnail')->getClientOriginalName()) . '.' . Input::file('thumbnail')->getClientOriginalExtension();
Input::file('thumbnail')->move($this->path, $tb_name);
$tb_path = $this->path . '/' . $tb_name;
$data['thumbnail'] = $tb_path;
//create new theme
$theme = Theme::create($data);
//create theme images
if (Input::has('theme_images')) {
$theme_images = Input::get('theme_images');
foreach ($theme_images as $image) {
$idata = array('image' => $image['url'], 'name' => $image['name'], 'theme_id' => $theme->id);
ThemeImage::create($idata);
}
}
/**
* Create theme logs
* #Initial released.
*/
ThemeLog::create(['description' => '#Initial released.', 'changed_date' => new Datetime(), 'theme_id' => $theme->id]);
return Redirect::route('admin.themes.index')->with('message', 'Item had created!');
}