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


PHP News::update方法代码示例

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


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

示例1: update

 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(News $new, Request $request)
 {
     $new->update($request->except('image'));
     if ($request->hasFile('image')) {
         $file = $request->file('image');
         $filename = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension();
         $image = Carbon::now() . ' - ' . $filename . '.' . $extension;
         $destinationPath = public_path('/uploads/images/');
         $request->file('image')->move($destinationPath, $image);
         $new->image = $image;
         $new->update();
     }
     flash()->info('Berita telah diperbarui!');
     return redirect('/dashboard/news');
 }
开发者ID:kobeuu,项目名称:bpb-sf,代码行数:22,代码来源:NewsController.php

示例2: update

 public function update(News $news, Request $request)
 {
     //dd($request->all());
     $user = $this->user;
     $this->validate($request, ['title' => 'required', 'content' => 'required', 'status' => 'required | in:0,1']);
     if ($request->hasFile('image')) {
         $this->validate($request, ['image' => 'mimes:jpeg,jpg,png,bmp,gif | max:1024']);
         $imageName = $this->uploadImage($request->file('image'));
         // delete the last image if exist
         $path = public_path('images/news/') . '/' . $news->image;
         if (File::exists($path)) {
             File::delete($path);
         }
     } else {
         $imageName = $news->image;
         //old image name
     }
     $news->update(['title' => $request->input('title'), 'content' => $request->input('content'), 'status' => $request->input('status'), 'user_id' => $user->id, 'image' => $imageName]);
     /*
      * Register Update Tags
      */
     $selected = $this->registerTags($request);
     //آی دی های تگ های جدید
     $news->tags()->sync($selected);
     //sync -> insert new tag and remove old tags
     Flash::success(trans('messages.newsEdited'));
     return redirect()->back();
 }
开发者ID:slifer2015,项目名称:tarabar,代码行数:28,代码来源:NewsController.php

示例3: update

 /**
  * Update the specified resource in storage.
  *
  * @param  \App\Http\Requests\NewsRequest $request
  * @param  \App\News $news
  * @return \Illuminate\Http\Response
  */
 public function update(Requests\NewsRequest $request, News $news)
 {
     DB::transaction(function () use($request, $news) {
         $update = ['active' => $request->get('active'), 'sort' => $request->get('sort')];
         if ($this->systemAdmin) {
             $update['department_id'] = $request->get('department_id');
         }
         $news->update($update);
         foreach ($news->langs as $lang) {
             $lang->update(['title' => $request->get('title_' . systemTrans($lang['lang_id'])), 'description' => $request->get('description_' . systemTrans($lang['lang_id']))]);
         }
     });
     return redirect(action('Admin\\NewsController@index'))->with('success', 'updated');
 }
开发者ID:Tisho84,项目名称:conference,代码行数:21,代码来源:NewsController.php


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