当前位置: 首页>>代码示例>>PHP>>正文


PHP Post::user方法代码示例

本文整理汇总了PHP中app\Post::user方法的典型用法代码示例。如果您正苦于以下问题:PHP Post::user方法的具体用法?PHP Post::user怎么用?PHP Post::user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Post的用法示例。


在下文中一共展示了Post::user方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: destroy

 public function destroy(Post $post)
 {
     if ($post->user()->getResults() != Auth::user()) {
         return response('Unauthorized.', 401);
     }
     return view('posts.show', compact($post->delete()));
 }
开发者ID:khaled-barca,项目名称:MyTunnelVision,代码行数:7,代码来源:PostController.php

示例2: bundlePost

 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;
 }
开发者ID:nehero,项目名称:updoot,代码行数:31,代码来源:SubdootController.php

示例3: handle

 /**
  * 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);
 }
开发者ID:robertzibert,项目名称:learning_laravel_5.1,代码行数:16,代码来源:PublishPost.php

示例4: store

 /**
  * 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 !");
 }
开发者ID:shempignon,项目名称:laravel-5-blog-mvc,代码行数:17,代码来源:PostController.php

示例5: makePost

 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;
 }
开发者ID:captainblue2013,项目名称:Lumen,代码行数:11,代码来源:TestCase.php

示例6: store

 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);
 }
开发者ID:captainblue2013,项目名称:Lumen,代码行数:14,代码来源:PostsController.php

示例7: store

 /**
  * 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);
 }
开发者ID:uTosTan,项目名称:codesamples,代码行数:23,代码来源:PostController.php

示例8: store

 /**
  * 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);
 }
开发者ID:uTosTan,项目名称:codesamples,代码行数:25,代码来源:TopicController.php


注:本文中的app\Post::user方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。