當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Post::fill方法代碼示例

本文整理匯總了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');
 }
開發者ID:NCKU-Official,項目名稱:ncku-report-server,代碼行數:34,代碼來源:PostController.php

示例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');
 }
開發者ID:jeremytubbs-deprecated,項目名稱:L51-Start-Here,代碼行數:17,代碼來源:PostsController.php

示例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]);
 }
開發者ID:kfwong,項目名稱:cvwo-assignment-1,代碼行數:17,代碼來源:PostController.php

示例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');
 }
開發者ID:vladzur,項目名稱:werken,代碼行數:21,代碼來源:PostsController.php

示例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');
 }
開發者ID:jrafaelca,項目名稱:infrea,代碼行數:24,代碼來源:PostsController.php

示例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);
     }
 }
開發者ID:herman-rogers,項目名稱:WestCoastSoftwareWebsite,代碼行數:27,代碼來源:PostController.php


注:本文中的app\Post::fill方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。