本文整理汇总了PHP中News::findOrFail方法的典型用法代码示例。如果您正苦于以下问题:PHP News::findOrFail方法的具体用法?PHP News::findOrFail怎么用?PHP News::findOrFail使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类News
的用法示例。
在下文中一共展示了News::findOrFail方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getThumbsDown
public function getThumbsDown($id)
{
try {
$valid_ip = Thumb::where('ip', '=', Puskice::getIP())->where('object_type', '=', 5)->where('object_id', '=', $id)->first();
if ($valid_ip != null) {
throw new Exception("Error valid IP", 1);
}
$news = News::findOrFail($id);
$news->thumbs_down++;
$news->save();
$thumb = new Thumb();
$thumb->ip = Puskice::getIP();
$thumb->object_id = $news->id;
$thumb->object_type = 5;
$thumb->save();
$thumbs = array();
if (Cookie::get('ps_thumbs')) {
$cookie = Cookie::get('ps_thumbs');
$thumbs = unserialize($cookie);
if (isset($thumbs['page'][$news->id])) {
return Response::json(array('status' => 'fail', 'message' => __("Већ сте оценили ову вест")));
}
}
$thumbs['page'][$news->id] = 'down';
Cookie::queue('ps_thumbs', serialize($thumbs), 2628000);
return Response::json(array('status' => 'success', 'message' => _("Ваш глас је забележен. Хвала на труду"), 'thumbsUp' => $news->thumbs_up, 'thumbsDown' => $news->thumbs_down));
} catch (Exception $e) {
return Response::json(array('status' => 'fail', 'message' => _("Већ сте оценили ову страницу")));
}
}
示例2: show
public function show($id)
{
$news = News::findOrFail($id);
$data['room'] = Rooms::select('roomtype.RoomType_Name', 'roomtype.ID_RoomType', 'roomtype_pic.Picture')->join('roomtype_pic', 'roomtype.ID_RoomType', '=', 'roomtype_pic.ID_RoomType')->where('roomtype_pic.Main_Pic', '=', 'YES')->where('roomtype.Status', '=', 'Active')->take(40)->get()->all();
$data['offer'] = Offer::where('Status', '=', 'Active')->take(40)->get()->all();
$data['about'] = About::get()->all();
return View::make('News.show', compact('news'))->with('news_active', 'active')->with('data', $data);
}
示例3: update
/**
* Update the specified news in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
$news = News::findOrFail($id);
$validator = Validator::make($data = Input::all(), News::$rules);
if ($validator->fails()) {
return Redirect::back()->withErrors($validator)->withInput();
}
$news->update($data);
return Redirect::route('news.index');
}
示例4: find
/**
* @param $id
* @return mixed
*/
public function find($id)
{
return $this->news->findOrFail($id);
}
示例5: getDelete
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function getDelete($id)
{
if (Session::get('user_level') < Config::get('cms.deleteNews')) {
return Redirect::to(_l(URL::action('AdminHomeController@getIndex')))->with('message', Lang::get('admin.notPermitted'))->with('notif', 'warning');
}
try {
$news = News::findOrFail($id);
$news->comments()->delete();
$news->subjects()->delete();
$news->files()->delete();
$news->delete();
return Redirect::to(_l(URL::action('NewsController@getIndex')))->with('message', Lang::get('admin.newsDeleted'))->with('notif', 'success');
} catch (Exception $e) {
return Redirect::to(_l(URL::action('NewsController@getIndex')))->with('message', Lang::get('admin.noSuchNews'))->with('notif', 'danger');
}
}
示例6: getCreate
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function getCreate($id)
{
if (Session::get('user_level') < Config::get('cms.editComments')) {
return Redirect::to(_l(URL::action('AdminHomeController@getIndex')))->with('message', Lang::get('admin.notPermitted'))->with('notif', 'warning');
}
try {
$_SESSION['RF']['subfolder'] = 'images/';
$news = News::findOrFail($id);
$this->setLayout();
View::share('title', Lang::get('admin.newComment') . ": " . dots($news->title, 60));
View::share('news', $news);
View::share('id', $id);
$this->layout->content = View::make('backend.comments.create');
} catch (Exception $e) {
return Redirect::to(_l(URL::action('CommentController@getIndex')))->with('message', Lang::get('admin.noSuchComment'))->with('notif', 'danger');
}
}
示例7: postCreate
public function postCreate($id)
{
try {
$this->googleAnalytics('/comments/create/' . $id);
$comment = new Comment();
$news = News::findOrFail($id);
if (Input::get('createdAt')) {
$comment->created_at = date("Y-m-d H:i:s", strtotime(Input::get('createdAt')));
} else {
$comment->created_at = date("Y-m-d H:i:s", strtotime('now'));
}
$comment->comment_content = Input::get('commentContent');
$akismet = new Akismet('http://www.puskice.org/', '5fa6e0236f7b');
$akismet->setCommentAuthor($comment->username);
$akismet->setCommentAuthorEmail($comment->email);
$akismet->setCommentAuthorURL("");
$akismet->setCommentContent($comment->comment_content);
$akismet->setPermalink('http://www.puskice.org/vest/' . Puskice::dateToUrl($news->created_at) . '/' . $news->permalink);
if ($akismet->isCommentSpam()) {
$comment->deleted_at = date('Y-m-d H:i:s', strtotime('now'));
}
if (Input::get('user_id')) {
$comment->published = 1;
} else {
$comment->published = 0;
}
if (Input::get('user_id')) {
$user = User::find(Input::get('user_id'));
$comment->username = $user->username;
$comment->email = $user->email;
} else {
$comment->username = Input::get('username');
$comment->email = Input::get('email');
}
if (Input::get('user_id')) {
$comment->user_id = Input::get('user_id');
} else {
$comment->user_id = 0;
}
$comment->news_id = $id;
$comment->ip_address = Puskice::getIP();
$comment->save();
if ($comment->deleted_at == null) {
$user = array('email' => 'info@puskice.org', 'name' => 'Info tim');
// the data that will be passed into the mail view blade template
$data = array('url' => "http://www.puskice.org/" . Config::get('settings.admin_url') . "/comments/edit/" . $comment->id, 'approve_url' => "http://www.puskice.org/" . Config::get('settings.admin_url') . "/comments/publish/" . $comment->id, 'delete_url' => "http://www.puskice.org/" . Config::get('settings.admin_url') . "/comments/trash/" . $comment->id, 'username' => $comment->username, 'email' => $comment->email, 'title' => $news->title, 'news' => 1, 'news_id' => $news->id, 'content' => $comment->comment_content);
// use Mail::send function to send email passing the data and using the $user variable in the closure
Mail::send('emails.new_comment', $data, function ($message) use($user) {
$message->from('info@puskice.org', "Puškice cenzura");
$message->to('info@puskice.org', 'Info tim Puškice')->subject('Novi komentar čeka moderaciju');
});
}
return Response::json(array('status' => 'success', 'message' => __("Ваш коментар је успешно прослеђен")));
} catch (Exception $e) {
return Response::json(array('status' => 'fail'));
}
}
示例8: postStore
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function postStore()
{
if (Session::get('user_level') < Config::get('cms.addFile')) {
return Redirect::to(_l(URL::action('AdminHomeController@getIndex')))->with('message', Lang::get('admin.notPermitted'))->with('notif', 'warning');
}
$rules = array('description' => 'Required', 'url' => 'Required', 'title' => 'Required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
return Redirect::to(_l(URL::action('FileController@getCreate') . '/' . Input::get('newsId')))->withErrors($validator)->withInput();
} else {
try {
$news = News::findOrFail(Input::get('newsId'));
$file = new Files();
if (Input::get('createdAt')) {
$file->created_at = date("Y-m-d H:i:s", strtotime(Input::get('createdAt')));
} else {
$file->created_at = date("Y-m-d H:i:s", strtotime('now'));
}
$file->description = Input::get('description');
$file->published = Input::get('published');
$file->user_id = Session::get('id');
$file->url = Input::get('url');
$file->news_id = Input::get('newsId');
$file->title = Input::get('title');
$file->save();
return Redirect::to(_l(URL::action('FileController@getEdit') . "/" . $file->id))->with('message', Lang::get('admin.fileSaved'))->with('notif', 'success');
} catch (Exception $e) {
return Redirect::to(_l(URL::action('FileController@getIndex')))->with('message', Lang::get('admin.noSuchFile'))->with('notif', 'danger');
}
}
}
示例9: get_newsremove
public function get_newsremove($id)
{
$news = News::findOrFail($id);
//This should be easy...
$news->delete();
return Redirect::route('consolenews')->with("message", "The news item was successfully removed and is subsequently no longer visible");
}