/** * Store a newly created resource in storage. * * @return Response */ public function store(BlogRequest $request) { $blog = new Blog($request->except('image', 'tags')); if ($request->hasFile('image')) { $file = $request->file('image'); $filename = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension() ?: 'png'; $folderName = '/uploads/blog/'; $picture = str_random(10) . '.' . $extension; $blog->image = $picture; } $blog->user_id = Sentinel::getUser()->id; $blog->save(); if ($request->hasFile('image')) { $destinationPath = public_path() . $folderName; $request->file('image')->move($destinationPath, $picture); } $blog->tag($request->tags); if ($blog->id) { return redirect('admin/blog')->with('success', trans('blog/message.success.create')); } else { return Redirect::route('admin/blog')->withInput()->with('error', trans('blog/message.error.create')); } }
/** * Store a newly created resource in storage. * * @return Response */ public function postCreate(BlogRequest $request) { $blog = new Blog($request->except('image', 'tags')); $picture = ""; if ($request->hasFile('image')) { $file = $request->file('image'); $filename = $file->getClientOriginalName(); $extension = $file->getClientOriginalExtension() ?: 'png'; $folderName = '/uploads/blog/'; $picture = str_random(10) . '.' . $extension; } $blog->user_id = Sentinel::getUser()->id; $blog->image = $picture; $blog->save(); if ($request->hasFile('image')) { $destinationPath = public_path() . $folderName; $request->file('image')->move($destinationPath, $picture); } $blog->tag($request['tags']); return redirect('admin/blog'); }