當前位置: 首頁>>代碼示例>>PHP>>正文


PHP News::find方法代碼示例

本文整理匯總了PHP中app\News::find方法的典型用法代碼示例。如果您正苦於以下問題:PHP News::find方法的具體用法?PHP News::find怎麽用?PHP News::find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\News的用法示例。


在下文中一共展示了News::find方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: news

 public function news(Request $request)
 {
     if ($request->isMethod('POST')) {
         //            News::create($request->except('_token'));
         // read image from temporary file
         $file = $request->file('imagePrev');
         $img = Image::make($file->getRealPath());
         $nameFile = $file->getClientOriginalName();
         //          resize image
         $img->fit(263, 263);
         // save image
         $img->save("images/" . $nameFile);
         News::create(['text' => $request->input('editor1'), 'header' => $request->input('header'), 'picture' => "images/" . $nameFile]);
         //            switch ( $request->input('type') ) {
         //                case 'insert':
         //                    News::create($request->except('_token'));
         //                    break;
         //                case 'update':
         //                    News::find( $request->input('id') )->update([
         //                        'header' => $request->input('header'),
         //                        'text' => $request->input('editor1'),
         //                    ]);
         //                    break;
         //            }
     }
     if ($request->isMethod('GET')) {
         $item = News::find($request->input('remove'));
         if ($item) {
             $item->delete();
         }
     }
     $news = News::orderBy('created_at', 'DESC')->paginate(15);
     return view('admin/news', ['news' => $news]);
 }
開發者ID:GraninNikita,項目名稱:feo,代碼行數:34,代碼來源:AdminController.php

示例2: edit

 /**
  * Show the form for editing the specified news.
  *
  * @param  int  $id
  * @return \Illuminate\View\View
  */
 public function edit($id)
 {
     $news = News::find($id);
     $direction = News::$direction;
     $language = News::$language;
     return view('admin.news.edit', compact('news', "direction", "language"));
 }
開發者ID:AmirHome,項目名稱:AmirHome,代碼行數:13,代碼來源:NewsController.php

示例3: show

 public function show($id)
 {
     $news = News::find($id);
     $news->visit++;
     $news->save();
     return view('news.show')->withNavSelection(3)->withTagSelection(-1)->withNews($news);
 }
開發者ID:AranKyun,項目名稱:SKLSE-website,代碼行數:7,代碼來源:NewsController.php

示例4: delete_news

 public function delete_news(Request $request)
 {
     $id = $request->item_id;
     $news = News::find($id);
     $news->delete();
     return back()->with('message', "Новость удалена");
 }
開發者ID:steverovsky,項目名稱:cycle-store,代碼行數:7,代碼來源:NewsController.php

示例5: show

 public function show($id)
 {
     $article = News::find($id);
     $year = Carbon::now();
     $year = $year->year;
     return view('shownews')->with('article', $article)->with('year', $year);
 }
開發者ID:silent-sea,項目名稱:silent-sea,代碼行數:7,代碼來源:NewsController.php

示例6: edit

 /**
  * Show the form for editing the specified news.
  *
  * @param  int  $id
  * @return \Illuminate\View\View
  */
 public function edit($id)
 {
     $news = News::find($id);
     $sitelanguages = Sitelanguages::site_access()->join('sites', function ($join) {
         $join->on('sites.id', '=', 'sitelanguages.sites_id');
     })->join('languages', 'languages.id', '=', 'sitelanguages.languages_id')->select('sitelanguages.id', \DB::raw(' CONCAT(sites.title, \'-\',languages.code) as site_language'))->get()->lists('site_language', 'id')->prepend('Please select', '');
     $category = Category::site_access()->join('sitelanguages', 'sitelanguages.id', '=', 'category.sitelanguages_id')->join('languages', 'languages.id', '=', 'sitelanguages.languages_id')->join('sites', 'sites.id', '=', 'sitelanguages.sites_id')->select('category.id', 'category.title')->get()->lists('title', 'id')->prepend('Please select', '');
     return view('admin.news.edit', compact('news', "sitelanguages", "category"));
 }
開發者ID:AmirHome,項目名稱:CMS_20160115,代碼行數:15,代碼來源:NewsController.php

示例7: delete

 public function delete($id)
 {
     $entry = News::find($id);
     if (isset($entry)) {
         News::where('id', $id)->update(array('trash' => 1));
         return \Redirect::route('news')->with('success', $entry->title . ' deleted succesfully!');
     } else {
         return \Redirect::route('news')->with('error', 'Failed to delete, invalid credentials.');
     }
 }
開發者ID:VertexDezign,項目名稱:VertexDezign,代碼行數:10,代碼來源:BackendNewsController.php

示例8: update

 public function update(Requests\NewsFormRequest $request, $id)
 {
     $news = News::find($id);
     $news->headline = $request->input('headline');
     $news->message = $request->input('message');
     $news->image = $request->file('image')->getClientOriginalName();
     $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,代碼行數:11,代碼來源:NewsController.php

示例9: show

 /**
  * Display the specified news article.
  *
  * @param  int  $id - id of a news artical
  * @return Response
  */
 public function show($id)
 {
     // find by $id
     $news_item = News::find($id);
     // if no news item found
     if (!$news_item) {
         // set response as an error
         return Response()->json(['message' => 'The news article could not be found', 'code' => 404], 404);
     }
     // set response as json with data
     return Response()->json(['data' => $news_item, 'code' => 200], 200);
 }
開發者ID:elistone,項目名稱:simple-news-api,代碼行數:18,代碼來源:NewsController.php

示例10: edit

 public function edit($id, $extra = array())
 {
     $news = \App\News::find($id);
     $extra['types'] = array('news' => 'Frétt');
     $extra['images'] = ['' => ' - Veldu mynd - '];
     if ($news->img()->exists()) {
         foreach ($news->img()->all() as $k => $img) {
             $extra['images'][$img['name']] = $img['name'];
         }
     }
     return parent::edit($id, $extra);
 }
開發者ID:stjanilofts,項目名稱:ofncms,代碼行數:12,代碼來源:NewsController.php

示例11: getShow

 /**
  * Отображает одну новость.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function getShow($id)
 {
     // Получаем новость из БД
     $data['news'] = News::find($id);
     if (!empty($data['news'])) {
         // Последние 3 новости
         $data['latest_news'] = News::where('id', '<>', $id)->orderBy('created_at', 'DESC')->take(3)->get();
         // Отображаем представление
         return view('marketing.news.show', $data);
     } else {
         abort(404);
     }
 }
開發者ID:alexmon1989,項目名稱:kadsgroup,代碼行數:19,代碼來源:NewsController.php

示例12: update

 public function update($id)
 {
     $aNewsData = Input::get('news');
     $validator = Validator::make($aNewsData, ['title' => 'sometimes|required|max:255', 'content' => 'sometimes|required', 'state' => 'sometimes|in:created,visible,deleted']);
     if ($validator->fails()) {
         $aRet = ['success' => 'false', 'errors' => $validator->errors()];
     } elseif ($oNews = News::find($id) and $oNews->fill($aNewsData)->update()) {
         $aRet = ['success' => 'true'];
     } else {
         $aRet = ['success' => 'false'];
     }
     return response()->json($aRet);
 }
開發者ID:kaeku,項目名稱:openzou,代碼行數:13,代碼來源:NewsServiceController.php

示例13: destroyNews

 public function destroyNews(Request $request)
 {
     $news = News::find($request->news_id);
     if ($news != NULL) {
         try {
             $news->delete();
             $message = array("reponse" => "success", "message" => "La news a bien été supprimée");
         } catch (\Exception $e) {
             $message = array("reponse" => "error", "message" => "Une erreur innatendue s'est produite");
         }
     } else {
         $message = array("reponse" => "error", "message" => "Une erreur innatendue s'est produite");
     }
     echo json_encode($message);
     return Redirect::route('AdminDisplayNews');
 }
開發者ID:prudywsh,項目名稱:tpe,代碼行數:16,代碼來源:AdminController.php

示例14: 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->validate($request, ['news_title' => 'required', 'news_text' => 'required']);
     $news = News::find($id);
     $news->is_published = $request->get('is_published') == 'on' ? 1 : 0;
     $news->title = $request->get('news_title');
     $news->text = $request->get('news_text');
     $news->save();
     $news->categories()->detach();
     if ($request->get('news_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', $news);
 }
開發者ID:poudigne,項目名稱:lcdj,代碼行數:24,代碼來源:NewsController.php

示例15: bulid_slugs

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function bulid_slugs()
 {
     $news = News::select(['id', 'title', 'keywords', 'content', 'language'])->get();
     foreach ($news as $news_item) {
         $news_record = News::find($news_item->id);
         if ('fa' == $news_item->language) {
             $news_record->title = persian_normalizer($news_item->title);
             $news_record->keywords = persian_normalizer($news_item->keywords);
             $news_record->content = persian_normalizer($news_item->content);
             $news_record->slug = persian_slug($news_item->title);
         } elseif ('tr' == $news_item->language) {
             $news_record->slug = turkish_slug($news_item->title);
         } else {
             $news_record->slug = str_slug($news_item->title);
         }
         $news_record->save();
     }
     return 'Done bulid slugs';
 }
開發者ID:AmirHome,項目名稱:AmirHome,代碼行數:24,代碼來源:NewsController.php


注:本文中的app\News::find方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。