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'); }
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); }
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')); }); }
/** * 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)); }
/** * 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'); }
public function adminEditPost(Request $request) { $post = Post::find($request->id); $post->content = $request->content; $post->save(); return back(); }
/** * 信件楼 * 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]); }
/** * 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'); }
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')); }
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]; }
public function show($id) { $post = Post::find($id); $comments = $post->comments; // return $comments; return view("posts/show")->with(['post' => $post, 'comments' => $comments]); }
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); }
/** * 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; }); }
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'); }
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; }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $post = Post::find($id); $post->update($request->except('_token')); // return 'posts.update: '; return redirect()->route('posts.edit', $post->id); }
public function gravaatualizacao(Request $request, $id) { $post = \App\Post::find($id); $post->fill($request->all()); $post->save(); return redirect('/post/index'); }
/** * Test Post -> Dificulty Level relationship * * @return void */ public function testPostDificultyLevelRelationship() { $this->assertTrue(Post::findOrFail(1) instanceof Post); $relationshipCollection = Post::find(1)->dificulty()->get(); $collection = collect([]); $this->assertTrue($relationshipCollection instanceof $collection); }
/** * Show post action, show one post. Search by slug first, * and if no result, search by id * * @param $id * @return \Illuminate\View\View */ public function getShowPost($id) { if (!($post = Post::where('slug', $id)->first())) { $post = Post::find((int) $id); } return view('front.showPost', compact('post')); }
/** * @param $id * @param $slug * @return the view of the active post */ public function showPost($id, $slug) { if (!($post = Post::where('slug', $id)->first())) { $post = Post::find((int) $id); } return view('front.blog.single', compact('post')); }
public function detail($id) { $category = Category::all(); $post = Post::find($id); $data = array('post' => $post, 'category' => $category); return view('blog.detail', $data); }
public function getView($id) { return view('view') ->with('title', 'Blog | Post') ->with('post', Post::find($id)) ->with('category', Category::all()); }
public function gravaatualizacao(Request $request, $id) { $post = \App\Post::find($id); $post->titulo = $request->input('titulo'); $post->texto = $request->input('texto'); $post->save(); redirect('post/index'); }
/** * Update the specified resource in storage. * Posts have user_id and text * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $post = \App\Post::find($id); $post->user_id = Auth::user()->id; $post->text = $request->text; $post->save(); return $post; }
public function showRecipie($id) { $recipie = Post::find($id); $recipie->views = $recipie->views + 1; $recipie->save(); Session::put('typepage', 'recipie'); return Redirect::to('/recipies/' . $recipie->slug)->with('tmprecipie', $recipie); }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $post = Post::find($id); if (!$post) { return $this->respondNotFound('Post does not exist.'); } return $this->respond(['data' => $this->postTransformer->transform($post)]); }
public function destroy($id) { $post = Post::find($id); foreach ($post->comments as $comment) { $comment->delete(); } return back()->with('message', 'Post wurde gelöscht...'); }
/** * Display a listing of the resource. * * @return Response */ public function index($id) { if (!Auth::check()) { return Redirect::to('/login'); } $post = Post::find($id); return view('post', ['post' => $post]); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { $user = User::find($id); $profile = Profile::find($user->id); $posts = Post::find($user); TrackerFunctions::log($user->name . " is viewing their own profile "); return view('profiles.default', compact('user', 'posts', 'profile')); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $post = Post::find($id); if (!$post) { throw new NotFoundHttpException('no post found'); } $post->delete(); return response()->json(['status' => 'post deleted'], 200); }