本文整理汇总了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()));
}
示例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;
}
示例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);
}
示例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 !");
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}