本文整理汇总了PHP中app\Article::whereId方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::whereId方法的具体用法?PHP Article::whereId怎么用?PHP Article::whereId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Article
的用法示例。
在下文中一共展示了Article::whereId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
/**
* Show the form required by an ajax request.
*
* @param $parent
* @param FormBuilder $formBuilder
*
* @return \Illuminate\Http\Response
*/
public function add(FormBuilder $formBuilder, $parent)
{
$articleComment = ArticleComment::whereId($parent)->get(['article_id'])->first();
$slug = Article::whereId($articleComment->article_id)->get(['slug'])->first();
$form = $formBuilder->create('\\App\\Http\\Forms\\ArticleCommentForm', ['method' => 'POST', 'id' => 'article_comment_form', 'url' => route('articles.comment.store')]);
$form->add('slug', 'hidden', ['value' => $slug->slug, 'attr' => ['id' => 'slug']]);
$form->add('parent_id', 'hidden', ['value' => $parent, 'attr' => ['id' => 'parent_id']]);
$form->add('save', 'submit', ['label' => 'Add your comment']);
return response()->view('articles.ajax_article_comment_show', compact('form'));
}
示例2: ajaxPostLike
/**
* ajax post like to article
*
* @param Request $request
* @param int $article_id
* @return Response
*/
public function ajaxPostLike(Request $request, $article_id)
{
// check authentication
if (!auth()->check()) {
return response()->json(['error' => 'user is not authenticated']);
}
// check the user has liked it or not
// temp plus variable
$plus = 1;
//-- get article
$article = Article::whereId($article_id)->first();
//-- get current user
$user = auth()->user();
// user has liked, decrement num_of_likes
if ($article->likeArticles()->whereUser_id($user->id)->first()) {
$plus = -1;
} else {
event(new PushNotification($article->user, $user->nickname . ' 喜歡您的文章 : ' . $article->title));
}
// determine to create LikeArticle or deleted liked record
if ($plus == 1) {
LikeArticle::create(['user_id' => $user->id, 'article_id' => $article_id]);
} else {
LikeArticle::whereUser_id($user->id)->whereArticle_id($article_id)->first()->delete();
}
// increment number of likes
$article->update(['num_of_likes' => $article->num_of_likes + $plus]);
return response()->json(['num_of_likes' => $article->num_of_likes]);
}
示例3: _authorize
/**
* Authorize the upload action of a picture album
* see the route list for details
*
* @param $model
* @param $model_id
* @param $id
*
* @return bool
*/
private function _authorize($model, $model_id, $id)
{
switch ($model) {
case 'user':
if ($id != 'new') {
$this->album = Album::where('id', $id)->first();
session(['album_id' => null]);
} else {
if (session('album_id') && session('album_id') != null) {
$this->album = Album::where('id', session('album_id'))->first();
} else {
$this->makeNewAlbum();
Auth::user()->albums()->save($this->album);
$this->album->update(['user_id' => Auth::id()]);
}
}
break;
case 'article':
$this->article = Article::whereId($id)->first();
if (!($this->album = Album::where('albumable_id', $id)->get()->first())) {
$this->makeNewAlbum();
$this->article->albums()->save($this->album);
}
break;
case 'profession':
$this->profession = Profession::whereId($id)->first();
if (!($this->album = Album::where('albumable_id', $id)->get()->first())) {
$this->makeNewAlbum();
$this->profession->albums()->save($this->album);
}
break;
case 'site':
$this->site = Site::whereId($model_id)->first();
if (!($this->album = Album::where('id', $id)->first())) {
if (!$this->site->albums->last()) {
$this->makeNewAlbum();
$this->site->albums()->save($this->site);
}
}
break;
case 'classified':
$this->classified = Classified::whereId($id)->first();
if (!($this->classified = Album::where('albumable_id', $id)->get()->first())) {
$this->makeNewAlbum();
$this->classified->albums()->save($this->album);
}
break;
}
//session(['album_id' => $this->album->id]);
return true;
}