本文整理汇总了PHP中app\News::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP News::findOrFail方法的具体用法?PHP News::findOrFail怎么用?PHP News::findOrFail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\News
的用法示例。
在下文中一共展示了News::findOrFail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
$news = News::findOrFail($id);
$news->delete();
\Flash::success('Nieuwsartikel verwijderd');
return redirect('admin/news');
}
示例2: update
public function update($id, CreateNewsRequest $request)
{
$news = News::findOrFail($id);
$news->update($request->all());
session()->flash('flash_message', 'Je artikel is succesvol aangepast');
return redirect('news');
}
示例3: update
/**
* Update the specified news in storage.
* @param UpdateNewsRequest|Request $request
*
* @param int $id
*/
public function update($id, UpdateNewsRequest $request)
{
$news = News::findOrFail($id);
$request = $this->saveFiles($request);
$news->update($request->all());
return redirect()->route('admin.news.index');
}
示例4: show
/**
* Display the specified resource.
*
* @param int $id
* @param Request $request
* @return Response
*/
public function show($id, Request $request)
{
$news = News::findOrFail($id);
if ($request->ajax()) {
return response()->json($news);
}
return $news;
}
示例5: update
/**
* Update the specified resource in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update(Request $request, $id)
{
$this->validate($request, ['title' => 'required']);
$item = News::findOrFail($id);
$item->update($request->all());
$item->saveImage($item, $request);
Flash::success("Запись - {$id} обновлена");
return redirect(route('admin.news.index'));
}
示例6: updateNews
public function updateNews($id, Request $request)
{
$news = News::findOrFail($id);
$this->validate($request, ['title' => 'required', 'content' => 'required']);
$input = $request->all();
$news->fill($input)->save();
Session::flash('flash_message', 'News successfully added!');
return redirect()->back();
}
示例7: getNewsArticle
/**
* Get a specific news article
* @param id
* @return JSON article
*/
public function getNewsArticle(Request $request)
{
try {
$path = explode("/", $request->path());
$id = $path[count($path) - 1];
$article = \App\News::findOrFail($id);
return $article->first();
} catch (ModelNotFoundException $e) {
return response()->json(['error' => 'invalid_id'], 401);
}
}
示例8: 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('link', function ($value) {
return Link::findOrFail($value);
});
$router->bind('news', function ($value) {
//news is name of wildcard
return News::findOrFail($value);
});
}
示例9: updateData
/**
* Helper untuk melakukan Update new Data ke dalam database
* @param int $id
*/
private function updateData($id = 0)
{
$data = News::findOrFail($id);
$data->judul = Input::get('judul');
$data->isi = Input::get('isi');
$file = Input::file('berita');
$image_name = time() . "-news-" . $file->getClientOriginalName();
$file->move(public_path() . '/upload', $image_name);
$data->image = $image_name;
$data->save();
return true;
}
示例10: 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 ($slug) {
return \Route::currentRouteName() == "articles.edit" ? \App\Article::findOrFail($slug) : \App\Article::published()->findOrFail($slug);
});
$router->bind('news', function ($id) {
return \Route::currentRouteName() == "news.edit" ? \App\News::findOrFail($id) : \App\News::published()->findOrFail($id);
});
$router->bind('tags', function ($name) {
return \App\Tag::where('name', $name)->firstOrFail();
});
$router->bind('users', function ($id) {
return \App\User::where('id', $id)->firstOrFail();
});
$router->bind('messages', function ($id) {
return \App\Message::where('id', $id)->firstOrFail();
});
$router->bind('registrants', function ($id) {
return \App\Registrant::where('id', $id)->firstOrFail();
});
$router->model('image', Image::class);
}
示例11: update
/**
* Update the news item in storage.
*
* @param Request $request
* @param int $id
* @return Response
*/
public function update($id, NewsRequest $request)
{
$news = News::findOrFail($id);
$news->update($request->all());
flash()->success('Your news item has been updated');
return redirect()->action('NewsController@edit', $news->id);
}
示例12: delete
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function delete($id)
{
$news = News::findOrFail($id);
$news->delete();
return Redirect::to('admin/newsList');
}
示例13: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$news = News::findOrFail($id);
try {
File::delete(public_path() . '/uploads/news/' . $news->image);
$news->destroy($id);
} catch (Exception $e) {
App::abort(404);
}
return Redirect::route('admin.index');
}
示例14: show
public function show($id)
{
$news = News::findOrFail($id);
return view('news.show')->with('news', $news);
}
示例15: postDeleteNews
public function postDeleteNews($id)
{
$news = News::findOrFail($id);
$news->delete(News::all());
return redirect('nieuws');
}