本文整理汇总了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]);
}
示例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"));
}
示例3: show
public function show($id)
{
$news = News::find($id);
$news->visit++;
$news->save();
return view('news.show')->withNavSelection(3)->withTagSelection(-1)->withNews($news);
}
示例4: delete_news
public function delete_news(Request $request)
{
$id = $request->item_id;
$news = News::find($id);
$news->delete();
return back()->with('message', "Новость удалена");
}
示例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);
}
示例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"));
}
示例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.');
}
}
示例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'));
}
示例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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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');
}
示例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);
}
示例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';
}