当前位置: 首页>>代码示例>>PHP>>正文


PHP News::save方法代码示例

本文整理汇总了PHP中app\News::save方法的典型用法代码示例。如果您正苦于以下问题:PHP News::save方法的具体用法?PHP News::save怎么用?PHP News::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\News的用法示例。


在下文中一共展示了News::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: save

 public function save()
 {
     $id = Request::input('id');
     $news = News::find($id);
     $flag = 0;
     if (!$news) {
         $news = new News();
         $flag = 1;
     }
     $news->title = Request::input('title');
     $news->description = Request::input('description');
     $news->active = Request::input('active');
     $news->date = Request::input('date');
     $news->save();
     if (Request::hasFile('img')) {
         $image = Input::file('img');
         $validator = Validator::make(array('image' => $image), array('image' => 'mimes:jpeg,bmp,png'));
         if ($validator->fails()) {
             $error_messages = $validator->messages();
             $message = "Invalid Input File";
             $type = "failed";
             return Redirect::to('admin/news/{id}/edit')->with('message', $message);
         } else {
             $news->image = upload_news_image(Input::file('img'));
             $news->save();
         }
     } else {
         if ($flag == 1) {
             //$news->image_url ="default_product.png";
         }
     }
     return redirect('admin/news/' . $news->id . '/edit');
 }
开发者ID:savitskayads,项目名称:skillcamp,代码行数:33,代码来源:NewsController.php

示例2: store

 public function store(Request $request)
 {
     $this->validate($request, ['title' => 'required|max:255', 'content' => 'required']);
     //process the html code
     $raw = $request->input('content');
     $code = "";
     //process img tag and save imgs
     while (preg_match("/<img([^>]*)src=\"data:image\\/(jpeg|gif|png);base64,([^\"]*)\"([^>]*)>/u", $raw, $matches, PREG_OFFSET_CAPTURE)) {
         $leftlength = $matches[0][1];
         $taglength = strlen($matches[0][0]);
         //save img file
         $data = base64_decode($matches[3][0]);
         $filename = md5($data) . "." . ($matches[2][0] == "jpeg" ? "jpg" : $matches[2][0]);
         if (!file_exists(public_path() . "/assets/images/news/" . $filename)) {
             $file = fopen(public_path() . "/assets/images/news/" . $filename, "w");
             fwrite($file, $data);
             fclose($file);
         }
         $code = $code . substr($raw, 0, $leftlength) . "<img" . $matches[1][0] . "src=\"_public_path/assets/images/news/" . $filename . "\"" . $matches[4][0] . "/>";
         $raw = substr($raw, $leftlength + $taglength);
     }
     $code = $code . $raw;
     //save in database
     $news = new News();
     $news->title = $request->input('title');
     $news->content = $code;
     $news->tag = $request->input('tag');
     if ($news->save()) {
         return Redirect::to('admin/news');
     } else {
         return Redirect::back()->withInput();
     }
 }
开发者ID:AranKyun,项目名称:SKLSE-website,代码行数:33,代码来源:NewsController.php

示例3: run

 public function run()
 {
     DB::table('news')->delete();
     $introduction = "Cras egestas non arcu quis facilisis. Etiam scelerisque felis a ante \n\t\tvehicula dignissim. Nunc nulla erat, placerat in ipsum efficitur, efficitur volutpat enim. \n\t\tIn nec lobortis sapien. Maecenas quis nunc molestie, ultrices magna nec, cursus risus. \n\t\tFusce viverra urna at blandit dignissim. Duis id porta augue, vel tempor enim. Ut eu orci dolor. ";
     $introduction1 = "Duis posuere cursus arcu, consectetur tincidunt turpis vulputate eu. \n\t\tInteger venenatis consequat turpis sit amet bibendum. Nulla nibh ex, semper nec sem sed, consectetur \n\t\ttincidunt metus. Aliquam mollis condimentum magna id tincidunt. Suspendisse pellentesque placerat \n\t\taccumsan. Sed a turpis lacus. Donec luctus lorem a turpis scelerisque tincidunt. Etiam at tellus \n\t\tsed erat elementum dictum. In sit amet nulla mattis, placerat erat non, vehicula metus. Morbi nulla \n\t\tsapien, sollicitudin non vulputate et, sodales in nisi. Donec sapien dolor, tincidunt sed ultricies \n\t\tin, ultrices sit amet ante. ";
     $content = "Quisque congue sed mauris sit amet fringilla. Pellentesque a justo mollis, \n\t\tlaoreet felis vehicula, elementum urna. Proin a nisl nec lorem mollis malesuada. Suspendisse sollicitudin \n\t\tvolutpat elementum. Mauris luctus egestas justo, nec tincidunt est luctus a. Aenean a convallis sem. \n\t\tAenean quis lorem efficitur, rutrum libero eu, efficitur nunc. Praesent eu metus pellentesque, mollis \n\t\tdui eget, interdum elit. Nulla tempus tristique eros, ut mattis leo sagittis at. Curabitur rutrum tellus \n\t\teu ex egestas, et dapibus lacus sodales. Maecenas facilisis tortor vitae neque vehicula, feugiat commodo \n\t\tnulla pulvinar. Maecenas porttitor mauris enim, sed condimentum enim varius vel. Nulla dapibus velit a \n\t\tluctus malesuada. Nam eleifend felis et porta semper. Proin blandit sem augue, in venenatis augue ultricies \n\t\tvitae. Nulla eu purus tellus.\n\rCras tempus mauris sed arcu euismod, eget ultrices nisi lobortis. Etiam \n\t\ttincidunt erat nunc, ut pretium turpis mollis et. Fusce feugiat, lectus id imperdiet rutrum, justo urna \n\t\tfinibus libero, eget dignissim erat lorem sed neque. Curabitur non nisl facilisis, venenatis risus vel, \n\t\tcommodo augue. Cras eget nisl dictum, sodales turpis eu, blandit lectus. Duis mattis est ac mi pretium \n\t\ttristique vitae non magna. Aenean dictum quis neque a volutpat. Integer convallis purus in enim tempor \n\t\tpretium. Sed sit amet diam et purus porta luctus. Sed pretium, lorem ut sodales maximus, nisl arcu \n\t\ttristique odio, nec posuere mauris metus ac justo. Pellentesque ut volutpat purus. Nulla vel ornare libero. \n\t\tSed metus massa, blandit eu lorem eu, finibus ornare arcu. Proin sagittis eu turpis sit amet scelerisque. \n\t\tPhasellus nec libero eu ipsum congue consectetur. Quisque id mattis nisl, ac porta sapien. Nulla lobortis,\n\t\tturpis at scelerisque finibus, augue neque laoreet diam, in facilisis lacus purus at libero. Ut libero \n\t\tsapien, laoreet nec lorem suscipit, efficitur tincidunt elit. Quisque mi libero, volutpat eu convallis nec, \n\t\tsemper at nulla. Sed hendrerit rhoncus nulla sit amet vestibulum. Vestibulum ante ipsum primis in faucibus \n\t\torci luctus et ultrices posuere cubilia Curae; Suspendisse diam neque, dignissim non metus maximus, \n\t\tsuscipit faucibus magna. Aenean sodales elit enim, eu laoreet dui vulputate ac. Donec sagittis dignissim \n\t\ttortor, vitae dignissim dolor ultricies eu. Vivamus rutrum vestibulum auctor. Aliquam eu orci ligula. \n\t\tQuisque at ligula ex. Suspendisse in ante eget turpis sollicitudin lobortis tincidunt sed nibh. Phasellus \n\t\telementum nibh vitae rutrum porta. Pellentesque vitae vestibulum purus. Curabitur placerat mattis tempor.";
     $news = new News();
     $news->language_id = 1;
     $news->user_id = 1;
     $news->newscategory_id = 1;
     $news->title = "Cras egestas non arcu quis facilisis";
     $news->introduction = $introduction;
     $news->content = $content;
     $news->save();
     $news = new News();
     $news->language_id = 1;
     $news->user_id = 1;
     $news->newscategory_id = 1;
     $news->title = "Fusce vel turpis ultricies";
     $news->introduction = $introduction1;
     $news->content = $content;
     $news->save();
     $news = new News();
     $news->language_id = 1;
     $news->user_id = 1;
     $news->newscategory_id = 1;
     $news->title = "Donec ligula sem, facilisis ac tristique et, imperdiet nec nisi";
     $news->introduction = $introduction;
     $news->content = $content;
     $news->save();
 }
开发者ID:ryleto,项目名称:nightjar,代码行数:31,代码来源:NewsTableSeeder.php

示例4: save

 public function save(NewsFormRequest $request)
 {
     $news = new News();
     $news->title = $request->title;
     $news->content = $request->description;
     $news->author_id = Auth::user()->id;
     $news->save();
     return back()->with('message', 'Новость сохранена');
 }
开发者ID:steverovsky,项目名称:cycle-store,代码行数:9,代码来源:NewsController.php

示例5: create

 public function create(Requests\CreateNewsRequest $request)
 {
     $title = $request->title;
     $shortdesc = $request->shortdesc;
     $content = $request->fullcontent;
     $news = new News();
     $news->title = $title;
     $news->shortdesc = $shortdesc;
     $news->content = $content;
     $news->save();
     return redirect('admin/news');
 }
开发者ID:silent-sea,项目名称:silent-sea,代码行数:12,代码来源:NewsController.php

示例6: addData

 /**
  * Helper untuk melakukan Add new Data ke dalam database
  * 
  */
 private function addData()
 {
     $data = new News();
     $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;
 }
开发者ID:semmiverian,项目名称:webJok,代码行数:16,代码来源:newsController.php

示例7: store

 public function store(Requests\NewsFormRequest $request)
 {
     $news = new News();
     $news->headline = $request->input('headline');
     $news->message = $request->input('message');
     $news->image = $request->file('image')->getClientOriginalName();
     $news->start_date = $request->input('start_date');
     $news->end_date = $request->input('end_date');
     $news->save();
     $request->file('image')->move(storage_path('app'), $news->image);
     $message = 'Successfully create news';
     return view('news.create', compact('message'));
 }
开发者ID:siwaphol,项目名称:med-site2,代码行数:13,代码来源:NewsController.php

示例8: storeNews

 public function storeNews(Request $request)
 {
     try {
         $news = new News();
         $news->title = $request->input('title');
         $news->description = $request->input('content');
         $news->slug = str_slug($request->input('title'));
         $news->user_id = $request->user()->id;
         $news->save();
     } catch (\Exception $e) {
         die($e);
     }
     return Redirect::route('AdminDisplayNews');
 }
开发者ID:prudywsh,项目名称:tpe,代码行数:14,代码来源:AdminController.php

示例9: create

 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create()
 {
     $title = Input::get('title');
     $text = Input::get('text');
     $tags = '<p><b>';
     $article = new App\News();
     $article->title = strip_tags($title, $tags);
     $article->text_news = strip_tags($text, $tags);
     $article->created_at = new \DateTime();
     $article->save();
     $last = App\News::orderby('id', 'desc')->first();
     $last['url'] = IndexController::translitURL($last['title']);
     $last['created'] = IndexController::restyleDate($last['created_at']);
     return ['article' => $last];
 }
开发者ID:ArtiResh,项目名称:mytest,代码行数:20,代码来源:IndexController.php

示例10: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $object = new Model();
     $params = $request->only('img', 'ru_title', 'ua_title', 'en_title', 'en_description', 'ua_description', 'ru_description', 'en_text', 'ru_text', 'ua_text', 'ru_seo_keywords', 'en_seo_keywords', 'ua_seo_keywords', 'ru_seo_description', 'en_seo_description', 'ua_seo_description');
     $filter = $object->validator($params);
     if ($filter->fails()) {
         $error = $filter->errors()->toArray();
         return view('admin.news.create', ['input' => $params, 'error' => $error]);
     }
     if ($request->hasFile('img')) {
         $params['img'] = $this->upload('img');
     }
     $object->fill($params);
     $object->save();
     return redirect('admin/news/' . $object->id);
 }
开发者ID:NickMomchev,项目名称:bautech,代码行数:22,代码来源:NewsController.php

示例11: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['news_title' => 'required', 'news_text' => 'required']);
     $news = new News();
     $news->is_published = $request->get('is_published') == 'on' ? 1 : 0;
     $news->title = $request->get('news_title');
     $news->text = $request->get('news_text');
     $news->save();
     if ($request->get('product_categories') != null) {
         foreach ($request->get('news_categories') as $category_id) {
             $news->categories()->attach($category_id);
         }
     }
     Session::flash('flash_message', 'Event successfully added!');
     return view('dashboard/create_news')->with('success', 1)->with('categories', Category::get())->with('news', new News());
 }
开发者ID:poudigne,项目名称:lcdj,代码行数:22,代码来源:NewsController.php

示例12: postAdd

 public function postAdd(Request $request)
 {
     $validator = $this->validator($request->all());
     if ($validator->fails()) {
         return redirect()->back()->withErrors($validator->messages())->withInput();
     }
     $item = new News();
     $item->title = $request->input('title');
     $item->description = $request->input('description');
     $item->content = $request->input('content');
     $file = $request->file('image');
     $imageExtension = $file->getClientOriginalExtension();
     $imageName = Slug::make($item->title) . '.' . $imageExtension;
     $request->file('image')->move(base_path() . '/public/images/news/', $imageName);
     $item->image = $imageName;
     $item->save();
     $msg = "Новость \"" . $item->title . "\" добавлена.";
     return redirect('admin/news')->with('msg', $msg);
 }
开发者ID:GorshkovNikita,项目名称:ruchaicof,代码行数:19,代码来源:NewsController.php

示例13: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     //
     $data = $request->all();
     if (isset($data['image'])) {
         $thumb = $data['image'];
         $new = 'ava' . uniqid() . '.' . $thumb->getClientOriginalExtension();
         $thumb->move('upload/news', $new);
     }
     $data['image'] = $new;
     $obj = new News();
     $obj->title = $data['title'];
     $obj->image = $data['image'];
     $obj->description = $data['description'];
     $obj->content = $data['content'];
     $obj->author_id = $data['author'];
     $obj->save();
     //return redirect('admin/users');
     return "Ok";
 }
开发者ID:nhunght,项目名称:mork_SmartOSC,代码行数:26,代码来源:NewsController.php

示例14: store

 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $news = new News();
     $news->fill($request->all());
     $slug = Helpers::makeSlug($request->input('title_geo'), 'news');
     if ($slug == "") {
         return Redirect::route('admin.index');
     }
     $news->slug = $slug;
     $image = $request->file('image');
     $fileName = "";
     if ($image->isValid()) {
         $path = public_path() . '/uploads/news/';
         $fileName = str_random(32) . '.' . $image->getClientOriginalExtension();
         $image->move($path, $fileName);
     } else {
         App::abort(404);
     }
     $news->image = $fileName;
     $news->save();
     return Redirect::route('admin.index');
 }
开发者ID:nikajorjika,项目名称:gamoiwere.ge,代码行数:28,代码来源:NewsController.php

示例15: postCreate

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postCreate(NewsRequest $request)
 {
     $news = new News();
     $news->user_id = Auth::id();
     $news->language_id = $request->language_id;
     $news->title = $request->title;
     $news->newscategory_id = $request->newscategory_id;
     $news->introduction = $request->introduction;
     $news->content = $request->content;
     $news->source = $request->source;
     $picture = "";
     if (Input::hasFile('picture')) {
         $file = Input::file('picture');
         $filename = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension();
         $picture = sha1($filename . time()) . '.' . $extension;
     }
     $news->picture = $picture;
     $news->save();
     if (Input::hasFile('picture')) {
         $destinationPath = public_path() . '/images/news/' . $news->id . '/';
         Input::file('picture')->move($destinationPath, $picture);
     }
 }
开发者ID:ryleto,项目名称:nightjar,代码行数:29,代码来源:NewsController.php


注:本文中的app\News::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。