public function destroy(Post $post) { if ($post->user()->getResults() != Auth::user()) { return response('Unauthorized.', 401); } return view('posts.show', compact($post->delete())); }
function bundlePost($request) { $data = $request->except(['subdoot']); $slugify = new Slugify(); $data['slug'] = $slugify->slugify($request->get('title'), '_'); if (strlen($data['slug']) > 46) { $data['slug'] = substr($data['slug'], 0, 46); } //6 character string for a permalink $permalink = $this->generateRandomString(); //Make sure the permalink is unique while (Post::wherePermalink($permalink)->exists()) { $permalink = $this->generateRandomString(); } $data['permalink'] = $permalink; //Insert the post into the db $post = new Post($data); //Attach the post to the user who created it //$post->user()->associate(\App\User::find(Auth::user()->id)); // $user = \App\User::find(Auth::user()->id); // $subdoot = Subdoot::find($request->get('subdoot')); // $user->posts()->save($post); // $subdoot->posts()->save($post); $post->user()->associate(\App\User::find(Auth::user()->id)); $post->save(); $post->subdoot()->associate(Subdoot::find($request->get('subdoot'))); $post->save(); //Attach the post to the subdoot it was submitted in //$post->subdoot()->associate(Subdoot::find($request->get('subdoot'))); return $post; }
/** * Execute the job. * * @return void */ public function handle() { //Creating post with all post data $post = new Post($this->post); //Associating one post with one user // Post->belongsTo User-> associate $post->user()->associate($this->user); $post->save(); //Attaching tags $post->tags()->attach($this->tags); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Requests\Post $request) { $category = Category::findOrFail($request->get('category_id')); $post = new Post($request->all()); $slug = $request->has('slug') ? $request->get('slug') : Str::slug($request->get('name')); $post->slug = $slug; $post->category()->associate($category); $post->user()->associate(Auth::user()); $post->save(); return redirect('/backend/posts')->withSucces($post->name . " has been created !"); }
protected function makePost($user = null) { if ($user == null) { $user = $this->makeUser(); } $post = new Post(); $post->content = $this->fake->sentences(10); $post->user()->associate($user); $post->save(); return $post; }
public function store() { $rules = ['text' => 'required']; $input = $_POST; $validator = Validator::make($input, $rules); if ($validator->fails()) { return $this->respondWithFailedValidation($validator); } $post = new Post(); $post->content = $input['content']; $post->user()->associate(Auth::user()); $post->save(); return $this->show($post->id); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $validator = Validator::make($request->all(), ['topic_id' => 'required|integer', 'content' => 'required']); if ($validator->fails()) { return response()->json(['errors' => $validator->errors()], 400); } $topic = Topic::find($request->topic_id); // use exception instead later if ($topic) { $post = new Post(); $post->content = $request->content; $post->user()->associate($this->user); $post->topic()->associate($topic); $post->save(); } return response()->json(['post' => $post], 201); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $token = JWTAuth::getToken(); $user = JWTAuth::toUser($token); $validator = Validator::make($request->all(), ['title' => 'required|max:255', 'content' => 'required']); if ($validator->fails()) { return response()->json(['errors' => $validator->errors()], 400); } $topic = new Topic(); $topic->title = $request->title; $topic->user()->associate($user); $topic->save(); $post = new Post(); $post->content = $request->content; $post->topic()->associate($topic); $post->user()->associate($user); $post->save(); return response()->json(['topic' => $topic, 'post' => $post], 201); }