本文整理汇总了PHP中app\Post::fill方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::fill方法的具体用法?PHP Post::fill怎么用?PHP Post::fill使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Post
的用法示例。
在下文中一共展示了Post::fill方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
/**
* Store a newly created resource in storage.
*
* @param CreatePostRequest $request
* @return Response
*/
public function store(CreatePostRequest $request, $category_id)
{
// save post
$post = new Post();
$post->fill($request->all());
$post->category_id = $category_id;
$post->save();
// if have attachment, create the attachment record
if ($request->hasFile('attachment')) {
// generate filename based on UUID
$filename = Uuid::generate();
$extension = $request->file('attachment')->getClientOriginalExtension();
$fullfilename = $filename . '.' . $extension;
// store the file
Image::make($request->file('attachment')->getRealPath())->resize(null, 640, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
})->save(public_path() . '/attachments/' . $fullfilename);
// attachment record
$attachment = new Attachment();
$attachment->post_id = $post->id;
$attachment->original_filename = $request->file('attachment')->getClientOriginalName();
$attachment->filename = $fullfilename;
$attachment->mime = $request->file('attachment')->getMimeType();
$attachment->save();
}
return redirect('category/' . $category_id . '/posts');
}
示例2: update
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update(Request $request, Post $post)
{
// update post
$post->user_id = \Auth::user()->id;
$post->slug = $request->get('title');
$post->html = $request->get('markdown');
$post->fill($request->all());
$post->featured = $request->has('featured') ? 1 : 0;
$post->save();
return redirect()->to('admin');
}
示例3: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$post = new Post();
$input = $request->all();
$input['post_author'] = Auth::user()->id;
$input['post_featured_image_url'] = "http://lorempixel.com/1000/500/fashion/" . random_int(1, 10);
$post->fill($input)->save();
Session::flash('status', 'Your blog post has been created successfully!');
$posts = Post::all();
return view('posts.show', ['post' => $post]);
}
示例4: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$post = new Post();
$post->fill($request->all());
$post->user_id = Auth::user()->id;
$post->slug = str_slug($post->title);
$post->draft = !empty($request->draft);
$post->save();
$tags = explode(',', $request->tags);
foreach ($tags as $tag) {
$tag_ids[] = Tag::getId($tag);
}
$post->tags()->sync($tag_ids);
return redirect('admin/posts');
}
示例5: store
/**
* Store a newly created resource in storage.
*
* @param CreatePostRequest $request
* @return Response
*/
public function store(CreatePostRequest $request)
{
$post = new Post();
$post->fill($request->all());
$post->user_id = Auth::id();
if ($request->hasFile('image')) {
$file = $request->file('image');
$patch = 'images/posts/';
$name = $post->title . '.' . $file->getClientOriginalExtension();
$image = $patch . $name;
Image::make($file)->fit(1140, 400)->save($image);
$post->image = $image;
}
$post->save();
$message = trans('messages.post_created_successfully');
Flash::success($message);
return redirect()->route('admin.posts.index');
}
示例6: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$input = $request->input('post');
try {
$validateData = $this->_validation->validate($input);
} catch (ValidationException $e) {
$errors['error'] = $e->get_errors();
return Response::json($errors, 422);
}
$createPost = new Post();
$response = ['post' => []];
try {
$statusCode = 200;
$response['post'] = $createPost->fill($input);
$createPost->save();
} catch (\Exception $e) {
Log::info($e);
$statusCode = 400;
} finally {
return Response::json($response, $statusCode);
}
}