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


PHP app\Post類代碼示例

本文整理匯總了PHP中app\Post的典型用法代碼示例。如果您正苦於以下問題:PHP Post類的具體用法?PHP Post怎麽用?PHP Post使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Post類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: newPost

 /**
  * Create a new post
  * @param string $body Content of post, will be run through filters
  * @param integer $threadid Thread ID
  * @param integer| $posterid Poster's ID. Defaults to currently authenticated user
  * @param bool|false $hidden Is the post hidden from normal view?
  * @param bool|true $save Should the post be automatically saved into the database?
  * @return Post The resulting post object
  */
 public static function newPost($body, $threadid, $posterid = null, $hidden = false, $save = true)
 {
     // Check users rights
     if (!Auth::check() && $posterid === null) {
         abort(403);
         // 403 Forbidden
     }
     // Check thread
     $thread = Thread::findOrFail($threadid);
     if ($thread->locked) {
         abort(403);
         // 403 Forbidden
     }
     // Run post through filters
     $body = PostProcessor::preProcess($body);
     // Create new post
     $post = new Post();
     $post->thread_id = $threadid;
     $post->poster_id = Auth::user()->id;
     $post->body = $body;
     $post->hidden = $hidden;
     // defaults to false
     // Put post into database
     if ($save) {
         $post->save();
     }
     return $post;
 }
開發者ID:harmjanhaisma,項目名稱:clearboard,代碼行數:37,代碼來源:Post.php

示例3: store

 public function store(PostsRequest $request)
 {
     $post = new Post();
     $post->title = $request->input('title');
     $post->content = $request->input('content');
     $post->save();
 }
開發者ID:Kristian95,項目名稱:LaravelApp,代碼行數:7,代碼來源:PostsController.php

示例4: removeCategory

 /**
  * Remove given category from given post.
  *
  * @param Post $post
  * @param Category $category
  * @return void
  * @throws NotFoundHttpException
  */
 public function removeCategory(Post $post, Category $category)
 {
     if (!$post->categories->contains($category->id)) {
         throw new NotFoundHttpException("Category doesn't exist on Post #" . $post->id);
     }
     $post->categories()->detach($category->id);
 }
開發者ID:lolzballs,項目名稱:website,代碼行數:15,代碼來源:PostRepository.php

示例5: apiStoreReply

 /**
  * API to store a new reply
  */
 public function apiStoreReply(ReplyRequest $request, Post $post)
 {
     logThis(auth()->user()->name . ' replied to ' . $post->title);
     $request->merge(['user_id' => auth()->user()->id]);
     $reply = $post->replies()->create($request->all());
     return $reply;
 }
開發者ID:goatatwork,項目名稱:goldaccess-support,代碼行數:10,代碼來源:RepliesController.php

示例6: store

 public function store(Request $request)
 {
     $post = new Post();
     $post->title = $request->title;
     $post->body = $request->body;
     $post->save();
 }
開發者ID:samyerkes,項目名稱:blog.samyerkes.com,代碼行數:7,代碼來源:PostController.php

示例7: postAddContent

 public function postAddContent()
 {
     $url = Input::get('url');
     if (strpos($url, 'youtube.com/watch?v=') !== FALSE) {
         $type = 'youtube';
         $pieces = explode("v=", $url);
         $mediaId = $pieces[1];
     } else {
         if (strpos($url, 'vimeo.com/channels/') !== FALSE) {
             $type = 'vimeo';
             $pieces = explode("/", $url);
             $mediaId = $pieces[5];
         } else {
             if (strpos($url, 'soundcloud.com/') !== FALSE) {
                 $type = 'soundcloud';
                 $mediaId = 'null';
             } else {
                 $type = 'other';
                 $mediaId = 'null';
             }
         }
     }
     $userId = Auth::id();
     $post = new Post();
     $post->url = $url;
     $post->type = $type;
     $post->userId = $userId;
     $post->mediaId = $mediaId;
     $post->save();
     return redirect('/content')->with('success', 'Post successfully created!');
 }
開發者ID:ChristofVanoppen,項目名稱:PHP2-MiniCMS,代碼行數:31,代碼來源:PostController.php

示例8: destroy

 public function destroy(Post $post)
 {
     $vote = Vote::where(['post_id' => $post->id, 'user_id' => Auth::user()->id])->first();
     $vote->delete();
     $post->decrement('vote_count');
     return response([]);
 }
開發者ID:enhive,項目名稱:vev,代碼行數:7,代碼來源:VoteController.php

示例9: create

 public function create($name, $title)
 {
     $post = new Post();
     $post->name = $name;
     $post->title = $title;
     $post->save();
     return $post;
 }
開發者ID:edisonthk,項目名稱:laravel5_reactjs,代碼行數:8,代碼來源:PostService.php

示例10: store

 public function store(Request $request, Post $post)
 {
     $comment = Comment::create($request->all());
     $post->comments()->save($comment);
     Score::create(['user_id' => Auth::user()->id, 'reference' => 'comment', 'score' => 2]);
     Auth::user()->increment('scores', 2);
     return redirect()->to('posts/' . $post->slug);
 }
開發者ID:enhive,項目名稱:vev,代碼行數:8,代碼來源:CommentController.php

示例11: handle

 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     $post = new Post();
     $post->user_id = $this->user_id;
     $post->title = $this->title;
     $post->message = $this->message;
     $post->save();
 }
開發者ID:pastoralbanojr,項目名稱:BlogNow,代碼行數:13,代碼來源:StorePost.php

示例12: destroy

 public function destroy(Post $post)
 {
     if ($post->image && \File::exists(public_path() . "/" . $post->image)) {
         \File::delete(public_path() . "/" . $post->image);
     }
     $post->delete();
     return redirect()->route("backend.post.index");
 }
開發者ID:erayaydin,項目名稱:erayaydin,代碼行數:8,代碼來源:PostController.php

示例13: create

 public function create(Request $request)
 {
     $this->validate($request, ['name' => 'required', 'topic' => 'required']);
     $post = new Post();
     $post->name = $request->input('name');
     $post->topic = $request->input('topic');
     $post->save();
     return response()->success(compact('post'));
 }
開發者ID:qjacquet,項目名稱:laravel-angular,代碼行數:9,代碼來源:PostsController.php

示例14: addNewPost

 public function addNewPost()
 {
     $title = Input::get("title");
     $body = Input::get("body");
     $importer_id = Auth::user()['attributes']['id'];
     $v = new Post();
     $v->title = $title;
     $v->body = $body;
     $v->importer_id = $importer_id;
     $v->save();
 }
開發者ID:navid1391,項目名稱:q._w-1947__bvcxryu--.-.-WWWQ___X_x_O_o,代碼行數:11,代碼來源:postController.php

示例15: changeStatus

 public function changeStatus(Post $post)
 {
     if ($post->status == 1) {
         $post->update(['status' => 0]);
         Flash::success(trans('admin/messages.postBan'));
     } elseif ($post->status == 0) {
         $post->update(['status' => 1]);
         Flash::success(trans('admin/messages.postActivate'));
     }
     return redirect()->back();
 }
開發者ID:emadmrz,項目名稱:Hawk,代碼行數:11,代碼來源:PostManagementController.php


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