本文整理汇总了PHP中app\Article::findOrfail方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::findOrfail方法的具体用法?PHP Article::findOrfail怎么用?PHP Article::findOrfail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Article
的用法示例。
在下文中一共展示了Article::findOrfail方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit
public function edit($id)
{
$article = Article::findOrfail($id);
$tags = \App\Tag::lists('name', 'id');
return view('articles.edit', compact('article', 'tags'));
}
示例2: destroy
public function destroy($id)
{
$article = Article::findOrfail($id);
$article->delete();
return redirect('admin/article')->with('flash_message', 'Article Succesfully Deleted!');
}
示例3: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Requests\EditArticleRequest $request, $id)
{
$article = Article::findOrfail($id);
$article->update($request->except('images'));
if ($request->images) {
$img = Image::make($request->images);
$mime = $img->mime();
//edited due to updated to 2.x
if ($mime == 'image/jpeg') {
$extension = '.jpg';
} elseif ($mime == 'image/png') {
$extension = '.png';
} elseif ($mime == 'image/gif') {
$extension = '.gif';
} else {
$extension = '';
}
$file = str_replace(' ', '-', $request->title . $extension);
$img->save(public_path('images/articles/' . $file));
$article->images = $file;
$article->save();
return redirect(route('articles.index'));
}
return redirect(route('articles.index'));
}
示例4: translate
public function translate($id)
{
$article = Article::findOrfail($id);
$categories = array_pluck($article->categories->toArray(), 'pivot.cat_id');
$new_article = Article::create(array_except($article->toArray(), ['id', 'created_at', 'updated_at', 'published_at', 'finished_at', 'status', 'lang', 'slug']) + ['published_at' => date('d/m/Y H:i'), 'status' => 0, 'lang' => '']);
$new_article->categories()->attach($categories);
flash()->success(trans('all.trans_item_created'));
return redirect(action('Admin\\PagesController@edit', $new_article->id));
}
示例5: show
public function show($id)
{
dd('show');
$article = Article::findOrfail($id);
return view('articles.show', compact('article'));
}