/** * Store a newly created resource in storage. * POST /banners * * @return Response */ public function store() { $validator = Validator::make($data = Input::all(), Banner::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } if (isset($data['banner_name'])) { $data = $this->uploadFile($data, 'banner_name'); } Banner::create($data); return Redirect::to('/banners')->withMessage("Created Banner"); }
public function create() { if (!$this->has_post()) { return redirect_message(array('admin', $this->get_class(), 'add'), array('_flash_message' => '非 POST 方法,錯誤的頁面請求。')); } $posts = OAInput::post(); $cover = OAInput::file('cover'); if (!$cover) { return redirect_message(array('admin', $this->get_class(), 'add'), array('_flash_message' => '請選擇照片(gif、jpg、png)檔案,或提供照片網址!', 'posts' => $posts)); } if ($msg = $this->_validation_posts($posts)) { return redirect_message(array('admin', $this->get_class(), 'add'), array('_flash_message' => $msg, 'posts' => $posts)); } $posts['sort'] = Banner::count(); $create = Banner::transaction(function () use($posts, $cover) { return verifyCreateOrm($banner = Banner::create(array_intersect_key($posts, Banner::table()->columns))) && $banner->cover->put($cover); }); if (!$create) { return redirect_message(array('admin', $this->get_class(), 'add'), array('_flash_message' => '新增失敗!', 'posts' => $posts)); } return redirect_message(array('admin', $this->get_class()), array('_flash_message' => '新增成功!')); }