本文整理汇总了PHP中app\Post::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::find方法的具体用法?PHP Post::find怎么用?PHP Post::find使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Post
的用法示例。
在下文中一共展示了Post::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: store
public function store()
{
$id = $this->request->input('id');
$input = $this->request->only(['provider', 'text', 'link', 'image']);
$categories = $this->request->input('categories');
$inputSchedule = $this->request->only(['schedule_date', 'schedule_time']);
if ($input['provider'] == 'weblink' && !$input['link']) {
throw new Exception('The "link" argument is missing', 1);
}
$post = (int) $id ? Post::find($id)->fill($input) : new Post($input);
if ($inputSchedule['schedule_date']) {
$time = explode(':', $inputSchedule['schedule_time']);
$date = new Carbon($inputSchedule['schedule_date']);
if (count($time) > 1) {
$date->setTime($time[0], $time[1]);
}
if ($date->timestamp > time()) {
$post->posted_at = $date;
}
} else {
$post->posted_at = new Carbon();
}
$post->user_id = $this->auth->id();
$post->save();
if (count($categories)) {
$post->categories()->sync($categories);
} else {
$post->categories()->detach();
}
$post->provider_id = $post->id;
$success = $post->save();
$job = (new PublishPost($post))->onQueue('publish');
$queued = $this->dispatch($job);
return compact('success', 'queued');
}
示例2: post
function post($id)
{
$data['post'] = Post::find($id);
$data['comments'] = Comment::where('post_id', '=', $id)->with('user')->get();
//$data['comments'] = Comment::find($id);
return view('blog/post', $data);
}
示例3: doUpdate
public function doUpdate($id, $request)
{
DB::transaction(function () use($id, $request) {
$post = Post::find($id);
$post->title = $request->input('title');
$post->content = $request->input('content');
$post->allow_comments = $request->input('allow_comments') !== null ? 1 : null;
if ($request->input('status') !== null && $request->input('status') == 'published') {
$post->status = 'published';
if ($request->input('published_at') !== null) {
$post->published_at = new \DateTime($request->input('published_at'));
} else {
$post->published_at = new \DateTime();
}
} else {
$post->status = 'draft';
$post->published_at = null;
}
$post->save();
$post->slug = $this->makeSlug($post);
$post->setCategories($post, $request->input('category_id'), $request->input('new_category'));
$post->setTags($post, commaListToArray($request->input('tags')));
//\File::cleanDirectory(app('http_cache.cache_dir'));
});
}
示例4: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy(Request $request)
{
$post = Post::find($request->post_id);
$topic = $post->topic_id;
$post->delete();
return Redirect::action('TopicController@show', array('id' => $topic));
}
示例5: destroy
/**
* Destroy the given post.
*
* @param Request $request
* @param string $postId
* @return Response
*/
public function destroy(Request $request, $postId)
{
$post = Post::find($postId);
$this->authorize('destroy', $post);
$post->destroy($postId);
return redirect('/posts');
}
示例6: adminEditPost
public function adminEditPost(Request $request)
{
$post = Post::find($request->id);
$post->content = $request->content;
$post->save();
return back();
}
示例7: store
/**
* 信件楼
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
if (!Auth::check()) {
return response()->json(['errno' => 2, 'msg' => 'require authentication']);
}
$pid = $request->input('pid');
$content = $request->input('content');
if (!$pid || !$content) {
return response()->json(['errno' => 1, 'msg' => 'require pid and content']);
}
$post = Post::find($pid);
if (!$post) {
return response()->json(['errno' => 3, 'msg' => 'post not found']);
}
$floor = new Floor();
$floor->pid = $pid;
$floor->uid = Auth::user()->id;
$floor->content = $content;
$floor->pics = $request->input('pics');
$floor->at_users = $request->input('at_users');
$floor->save();
//更新时间戳
$floor->post->touch();
return response()->json(['errno' => 0, 'msg' => 'success', 'floor' => $floor]);
}
示例8: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$like = Like::find($id);
$post = Post::find($like->post_id);
Like::destroy($id);
return redirect('users');
}
示例9: newPost
public function newPost(Request $request)
{
$post = $request->has('temp_id') ? Post::find($request->only(['temp_id'])) : null;
$title = is_null($post) ? null : $post->title;
$body = is_null($post) ? null : $post->body;
return view('admin.posts.new', compact('post', 'title', 'body'));
}
示例10: getAction
public function getAction($post = null, $action = null)
{
$post = Post::find($post);
if (!$post) {
app()->abort(422);
}
if ($action) {
// Log action and push to queue
$log = Log::firstOrNew(['reason' => $action, 'market_item_id' => $post->market()->whereAction($action)->first()->id]);
if (!$log->id) {
Auth::user()->log()->save($log);
$job = (new AwaitAction($log))->onQueue('check');
$this->dispatch($job);
} else {
return ['error' => trans('app.action_duplicate')];
}
}
if (!$post) {
return ['success' => true];
}
$url = !$action ? false : $this->social->with($post->provider)->action($action, $post->provider_id);
if ($url === true) {
return ['success' => true];
}
if (!$url || !parse_url($url)) {
$url = $post->link;
}
return ['success' => true, 'redirect' => $url];
}
示例11: show
public function show($id)
{
$post = Post::find($id);
$comments = $post->comments;
// return $comments;
return view("posts/show")->with(['post' => $post, 'comments' => $comments]);
}
示例12: comment
public function comment($id, Request $request)
{
$post = \App\Post::find($id);
$comment = \App\Comment::create($request->all());
$post->comments()->save($comment);
return redirect()->route('posts.show', $post->id);
}
示例13: boot
/**
* Register any application authentication / authorization services.
*
* @param \Illuminate\Contracts\Auth\Access\Gate $gate
* @return void
*/
public function boot(GateContract $gate)
{
$this->registerPolicies($gate);
$gate->before(function ($user, $ability) {
if (!$user->cmsEntry() && $ability != 'delete-comment') {
return false;
} else {
if ($user->is('SuperAdmin') && $ability != 'change-user') {
return true;
}
}
});
$gate->define('change-user', function ($user, $user2) {
if (($user->is('SuperAdmin') || $user->is('Admin')) && $user->rank() < $user2->rank()) {
return true;
}
return false;
});
$gate->define('features', function ($user) {
return $user->is('Admin');
});
$gate->define('create-post', function ($user) {
return $user->is('Admin') || $user->is('Writer');
});
$gate->define('change-post', function ($user, $id) {
if ($user->is('Writer')) {
return $user->id == Post::find($id)->user_id;
}
return $user->is('Admin');
});
$gate->define('delete-comment', function ($user, $comment) {
return $user->id == $comment->user->id;
});
}
示例14: accept
public function accept($id)
{
$offer = Offer::find($id);
$post = Post::find($offer->post_id);
$post->sold = $id;
$post->save();
$user = User::findOrFail($offer->user_id);
$poster = User::findOrFail($offer->post_creator);
$feedback_seller = new Feedback();
$feedback_seller->post_id = $offer->post_id;
$feedback_seller->giver_id = $offer->user_id;
$feedback_seller->receiver_id = $offer->post_creator;
$feedback_seller->type = 'seller';
$feedback_seller->save();
$feedback_buyer = new Feedback();
$feedback_buyer->post_id = $offer->post_id;
$feedback_buyer->giver_id = $offer->post_creator;
$feedback_buyer->receiver_id = $offer->user_id;
$feedback_buyer->type = 'buyer';
$feedback_buyer->save();
Mail::send('emails.offerAccepted', ['user' => $user, 'offer' => $offer, 'poster' => $poster, 'feedback' => $feedback_buyer], function ($m) use($user) {
$m->to($user->email, $user->name)->subject('Offer Accepted!');
});
Mail::send('emails.listingSold', ['user' => $user, 'offer' => $offer, 'poster' => $poster, 'feedback' => $feedback_seller], function ($m) use($user) {
$m->to($poster->email, $poster->name)->subject('Listing Sold!');
});
return Redirect($post->community_id . '/post/' . $post->id)->with('message', 'Offer Accepted');
}
示例15: postLikePost
public function postLikePost(Request $request)
{
$post_id = $request['postId'];
$isLike = $request['isLike'] === 'true';
// ? true : false;
$update = false;
$post = Post::find($post_id);
if (!$post) {
return null;
}
$user = Auth::user();
$like = $user->likes()->where('post_id', $post_id)->first();
if ($like) {
$alreadyLike = $like->like;
$update = true;
if ($alreadyLike == $isLike) {
$like->delete();
return null;
}
} else {
$like = new Like();
}
$like->like = $isLike;
$like->user_id = $user->id;
$like->post_id = $post->id;
if ($update) {
$like->update();
} else {
$like->save();
}
return null;
}