本文整理汇总了PHP中app\Article::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::findOrFail方法的具体用法?PHP Article::findOrFail怎么用?PHP Article::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Article
的用法示例。
在下文中一共展示了Article::findOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
//
parent::boot($router);
$router->bind('articles', function ($id) {
$article = Article::findOrFail($id);
// If the owner return all articles else return only published.
if (Auth::user() && $article->user_id === Auth::user()->id) {
$articles = Article::findOrFail($id);
} else {
$articles = Article::published()->findOrFail($id);
}
return $articles;
});
$router->bind('questions', function ($id) {
return Question::findOrFail($id);
});
$router->bind('answers', function ($id) {
return Answer::findOrFail($id);
});
$router->bind('tags', function ($name) {
return Tag::where('name', $name)->firstOrFail();
});
$router->bind('users', function ($id) {
return User::findOrFail($id);
});
}
示例2: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
// bind article
$router->model('article', 'App\\Article');
$router->bind('admin.article', function ($id) {
return \App\Article::findOrFail($id);
});
// bind category
$router->model('category', 'App\\Category');
$router->bind('admin.category', function ($id) {
return \App\Category::findOrFail($id);
});
// bind language
$router->model('language', 'App\\Language');
$router->bind('admin.language', function ($id) {
return \App\Language::findOrFail($id);
});
// bind language
$router->model('page', 'App\\Page');
$router->bind('admin.page', function ($id) {
return \App\Page::findOrFail($id);
});
// bind setting
$router->model('setting', 'App\\Setting');
$router->bind('admin.setting', function ($id) {
return \App\Setting::findOrFail($id);
});
// bind user
$router->model('user', 'App\\User');
$router->bind('admin.user', function ($id) {
return \App\User::findOrFail($id);
});
parent::boot($router);
}
示例3: blogShow
public function blogShow($id)
{
$article = Article::findOrFail($id);
$user = $article->user;
$photos = count($article->photos);
return view('blog.show', compact('article', 'photos', 'user'));
}
示例4: update
public function update($id, \Illuminate\Http\Request $request)
{
$this->validate($request, ['name' => 'required', 'text' => 'required']);
$article = Article::findOrFail($id);
$article->update($request->all());
return redirect('articles');
}
示例5: update
public function update($id, ArticleRequest $request)
{
$article = Article::findOrFail($id);
$article->tags()->sync($request->input('tag_list'));
$article->update($request->all());
return redirect('articles');
}
示例6: show
public function show($id)
{
$article = Article::findOrFail($id);
$categories = $this->categories();
$tags = Tag::all();
return view('home.single', compact('article', 'categories', 'tags'));
}
示例7: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$this->check($request);
$article = Article::findOrFail($id);
$article->update($request->all());
return redirect('/admin/articles');
}
示例8: showArticle
public function showArticle($id)
{
$article = Article::findOrFail($id);
$news = Article::where('id', '>', $article->id)->orderBy('id', 'DESC')->take(NEW_OLD_ARTICLE);
$olds = Article::where('id', '<', $article->id)->orderBy('id', 'DESC')->take(NEW_OLD_ARTICLE);
return view('frontend.articles.main')->with(compact('news', 'article', 'olds'));
}
示例9: update
public function update($id, Request $request)
{
$this->validate($request, ['title' => 'required', 'description' => 'required']);
$article = Article::findOrFail($id);
$article->update($request->all());
return redirect('articles');
}
示例10: update
/**
* Update the specified resource in storage.
*
* @param int $id
*
* @return Response
*/
public function update(ArticleRequest $request, $id)
{
$article = Article::findOrFail($id);
$article->update($request->all());
$this->syncTags($article, $request->input('tag_list'));
return redirect('admin/articles/index');
}
示例11: showarticle
public function showarticle($id)
{
$choosenLang = \Session::get('locale');
$tags = Tag::where('lang', '=', $choosenLang)->get();
$article = Article::findOrFail($id);
return view('showarticle', compact('article', 'tags'));
}
示例12: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Requests\ArticleRequest $request, $id)
{
$article = Article::findOrFail($id);
$article->update($request->all());
$article->tags()->sync($request->get('tag_list', []));
return redirect()->action('Goenitz\\ArticleController@index');
}
示例13: update
public function update($id, ClanakRequest $request)
{
$clanak = Article::findOrFail($id);
$clanak->update($request->all());
Session::flash('flash_message', 'Uspjesno ste izmjenili clanak');
return redirect('clanak');
}
示例14: update
public function update($id, Requests\ArticleRequest $request)
{
$article = Article::findOrFail($id);
$article->update($request->all());
$tagIds = $request->input('tag_list');
$this->syncTags($article, $tagIds);
return redirect('articles');
}
示例15: showpost
public function showpost($id)
{
//display one post
$article = Article::findOrFail($id);
$comment = Comment::where('postid', '=', $id)->get();
//if (is_null($article)) { abort(404); }
return view('articles.show', compact('article', 'comment'));
}