本文整理汇总了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');
}
示例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;
}
示例3: store
public function store(PostsRequest $request)
{
$post = new Post();
$post->title = $request->input('title');
$post->content = $request->input('content');
$post->save();
}
示例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);
}
示例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;
}
示例6: store
public function store(Request $request)
{
$post = new Post();
$post->title = $request->title;
$post->body = $request->body;
$post->save();
}
示例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!');
}
示例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([]);
}
示例9: create
public function create($name, $title)
{
$post = new Post();
$post->name = $name;
$post->title = $title;
$post->save();
return $post;
}
示例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);
}
示例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();
}
示例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");
}
示例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'));
}
示例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();
}
示例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();
}