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


PHP Product::onlyTrashed方法代码示例

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


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

示例1: update

 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $feedid, $id)
 {
     if (Input::has('action')) {
         // Filter 作業
         switch ($request->input('action')) {
             case 'enable':
                 $enable_checked = Input::get('enable');
                 if (is_array($enable_checked)) {
                     //
                     $products = Product::onlyTrashed()->whereIn('id', $enable_checked)->get();
                     foreach ($products as $product) {
                         $product->restore();
                     }
                     // redirect
                     return Redirect::back()->with('message', 'Products Activate successfully');
                     //return redirect()->action('FeedProductController@index', [$id])->with('message', 'Error !: KEY 值重複 Feed_id:[ '.$id.' ]已有產品ID[ '.$item->product_id.' ]');
                 }
                 break;
             case 'disable':
                 $disable_checked = Input::get('disable');
                 if (is_array($disable_checked)) {
                     //
                     $products = Product::whereIn('id', $disable_checked)->get();
                     foreach ($products as $product) {
                         $product->delete();
                     }
                     // redirect
                     //Session::flash('message', 'Successfully deleted the platform!');
                     return Redirect::back()->with('message', 'Product Disable successfully');
                     //return redirect()->action('FeedProductController@index', [$id])->with('message', 'Error !: KEY 值重複 Feed_id:[ '.$id.' ]已有產品ID[ '.$item->product_id.' ]');
                 }
                 break;
         }
     } else {
         // 單一產品資料更新
         $validator = Validator::make($request->all(), ['name' => 'required|max:255', 'description' => 'required|max:3000', 'url' => 'required|max:300|url', 'image' => 'required|max:300|url', 'price' => 'required|integer', 'retail_price' => 'required|integer', 'category' => 'required|max:100', 'google_category' => 'required|max:100', 'brand' => 'required|max:20', 'condition' => "required|in:new,used,refurbished", 'availability' => 'required|in:in stock,out of stock,preorder']);
         if ($validator->fails()) {
             //return redirect('admin/feeds/'.$feedid.'/product/'.$id)
             return Redirect::route('admin.feeds.product.edit', array($feedid, $id))->withInput()->withErrors($validator);
         }
         try {
             $product = Product::where('feed_id', $feedid)->where('id', $id)->first();
             $product->name = $request->input('name');
             $product->description = $request->input('description');
             $product->url = $request->input('url');
             $product->image = $request->input('image');
             $product->price = $request->input('price');
             $product->retail_price = $request->input('retail_price');
             $product->category = $request->input('category');
             $product->google_category = $request->input('google_category');
             $product->brand = $request->input('brand');
             $product->condition = $request->input('condition');
             $product->availability = $request->input('availability');
             $product->save();
         } catch (Exception $e) {
         }
         return Redirect::route('admin.feeds.product.index', array($feedid))->with('message', 'Save - 產品內容更新完成!');
     }
 }
开发者ID:shihqi,项目名称:fms,代码行数:66,代码来源:FeedProductController.php

示例2: handle

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     //
     $storage = Storage::disk('ftp');
     $files = Storage::disk('ftp')->files('/public_html/feed/complete');
     //$directories = Storage::disk('ftp')->directories('public_html');
     if (count($files) > 0) {
         //echo explode("_",basename($files[0]))[0];
         $contents = Storage::disk('ftp')->get($files[0]);
         // ip xml
         $dom = simplexml_load_string($contents) or die('feed file not loading');
         //echo count($dom->channel->item);
         for ($i = 0; $i < count($dom->channel->item); ++$i) {
             $products[] = array('id' => $dom->channel->item[$i]->product_id, 'name' => $dom->channel->item[$i]->product_name, 'description' => $dom->channel->item[$i]->product_description, 'url' => urldecode($dom->channel->item[$i]->product_url), 'image' => urldecode($dom->channel->item[$i]->product_image), 'category' => $dom->channel->item[$i]->product_category, 'brand' => $dom->channel->item[$i]->product_brand, 'condition' => $dom->channel->item[$i]->product_condition, 'availability' => $dom->channel->item[$i]->product_availability, 'price' => trim($dom->channel->item[$i]->product_price, ' TWD'), 'retail_price' => trim($dom->channel->item[$i]->product_retail_price, ' TWD'));
         }
         $feed = Feed::where('location', explode("_", basename($files[0]))[0])->firstOrFail();
         //echo explode("_",basename($files[0]))[0];
         //echo $feed->id;
         //var_dump($feed);
         $feedId = $feed->id;
         DB::beginTransaction();
         try {
             //  將已有的資料delete
             $affectedRows = Product::where('feed_id', $feedId)->delete();
             //
             foreach ($products as $item) {
                 //  已存在
                 $item['feed_id'] = $feedId;
                 if (Product::onlyTrashed()->where('feed_id', $feedId)->where('id', $item['id'])->exists()) {
                     //  restore
                     Product::onlyTrashed()->where('feed_id', $feedId)->where('id', $item['id'])->restore();
                     //  update
                     $affectedRows = Product::where('feed_id', $feedId)->where('id', $item['id'])->update($item);
                     $this->info('DB update:' . $item['id']);
                 } else {
                     //  insert
                     $insert = Product::create($item);
                     $this->info('DB insert:' . $item['id']);
                 }
             }
             DB::commit();
             // log
             $this->info(date('Y-m-d h:i:s') . ' DB commit:' . $feedId);
         } catch (\Exception $e) {
             DB::rollback();
             switch ($e->getCode()) {
                 case 23000:
                     //log
                     $this->error('DB 23000:' . $e->getLine() . $e->getCode() . $e->getMessage());
                     break;
                 default:
                     //log
                     $this->error('DB error:' . $e->getLine() . $e->getCode() . $e->getMessage());
             }
         }
         // 複製到完成資料夾
         Storage::disk('ftp')->copy($files[0], str_replace('complete', 'done/complete/' . date("Ymd"), $files[0]));
         //刪除原檔案
         Storage::disk('ftp')->delete($files[0]);
     } else {
         $files = Storage::disk('ftp')->files('/public_html/feed/modify');
         //$directories = Storage::disk('ftp')->directories('public_html');
         if (count($files) > 0) {
             //echo explode("_",basename($files[0]))[0];
             $contents = Storage::disk('ftp')->get($files[0]);
             // ip xml
             $dom = simplexml_load_string($contents) or die('feed file not loading');
             //echo count($dom->channel->item);
             $feed = Feed::where('location', explode("_", basename($files[0]))[0])->firstOrFail();
             $feedId = $feed->id;
             DB::beginTransaction();
             try {
                 //
                 for ($i = 0; $i < count($dom->channel->item); ++$i) {
                     // action
                     $action = $dom->channel->item[$i]->attributes()->action;
                     // product data
                     $products[] = array('feed_id' => $feedId, 'id' => $dom->channel->item[$i]->product_id, 'name' => $dom->channel->item[$i]->product_name, 'description' => $dom->channel->item[$i]->product_description, 'url' => urldecode($dom->channel->item[$i]->product_url), 'image' => urldecode($dom->channel->item[$i]->product_image), 'category' => $dom->channel->item[$i]->product_category, 'brand' => $dom->channel->item[$i]->product_brand, 'condition' => $dom->channel->item[$i]->product_condition, 'availability' => $dom->channel->item[$i]->product_availability, 'price' => trim($dom->channel->item[$i]->product_price, ' TWD'), 'retail_price' => trim($dom->channel->item[$i]->product_retail_price, ' TWD'));
                     // process
                     switch ($action) {
                         case "add":
                             if (Product::withTrashed()->where('feed_id', $feedId)->where('id', $item['id'])->exists()) {
                                 if (Product::onlyTrashed()->where('feed_id', $feedId)->where('id', $item['id'])->exists()) {
                                     //  restore
                                     Product::onlyTrashed()->where('feed_id', $feedId)->where('id', $item['id'])->restore();
                                     //  update
                                     $affectedRows = Product::where('feed_id', $feedId)->where('id', $item['id'])->update($item);
                                     $this->info('Product restore and update:' . $item['id']);
                                 } else {
                                     // add 的產品已存在
                                     $this->error('Product to add existed! ' . $item['id']);
                                 }
                             } else {
                                 //  insert
                                 $insert = Product::create($item);
//.........这里部分代码省略.........
开发者ID:shihqi,项目名称:fms,代码行数:101,代码来源:ParseFile.php

示例3: handle

 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     //
     $feedId = $this->argument('id');
     $feed = Feed::findOrFail($feedId);
     //$parser = new Parser();
     //$xml = $parser->xml('');
     //$item = array();
     $dom = simplexml_load_file($feed->location) or die('feed not loading');
     echo count($dom->channel->item);
     for ($i = 0; $i < count($dom->channel->item); ++$i) {
         $products[] = array('id' => $dom->channel->item[$i]->product_id, 'name' => $dom->channel->item[$i]->product_name, 'description' => $dom->channel->item[$i]->product_description, 'url' => urldecode($dom->channel->item[$i]->product_url), 'image' => urldecode($dom->channel->item[$i]->product_image), 'category' => $dom->channel->item[$i]->product_category, 'brand' => $dom->channel->item[$i]->product_brand, 'condition' => $dom->channel->item[$i]->product_condition, 'availability' => $dom->channel->item[$i]->product_availability, 'price' => trim($dom->channel->item[$i]->product_price, ' TWD'), 'retail_price' => trim($dom->channel->item[$i]->product_retail_price, ' TWD'));
     }
     DB::beginTransaction();
     try {
         switch ($feed->content) {
             case "complete":
                 //  將已有的資料delete
                 $affectedRows = Product::where('feed_id', $feedId)->delete();
                 //
                 foreach ($products as $item) {
                     //  已存在
                     $item['feed_id'] = $feedId;
                     if (Product::onlyTrashed()->where('feed_id', $feedId)->where('id', $item['id'])->exists()) {
                         //  restore
                         Product::onlyTrashed()->where('feed_id', $feedId)->where('id', $item['id'])->restore();
                         //  update
                         $affectedRows = Product::where('feed_id', $feedId)->where('id', $item['id'])->update($item);
                         $this->info('DB update:' . $item['id']);
                     } else {
                         //  insert
                         $insert = Product::create($item);
                         $this->info('DB insert:' . $item['id']);
                     }
                 }
                 break;
             case "modify":
                 //
                 foreach ($products as $item) {
                     //  已存在
                     $item['feed_id'] = $feedId;
                     if (Product::where('feed_id', $feedId)->where('id', $item['id'])->exists()) {
                         //  update
                         $affectedRows = Product::where('feed_id', $feedId)->where('id', $item['id'])->update($item);
                         $this->info('DB update:' . $item['id']);
                     } else {
                         //  insert
                         $insert = Product::create($item);
                         $this->info('DB insert:' . $item['id']);
                     }
                 }
                 break;
         }
         DB::commit();
         // log
         $this->info(date('Y-m-d h:i:s') . ' DB commit:' . $feedId);
     } catch (\Exception $e) {
         DB::rollback();
         switch ($e->getCode()) {
             case 23000:
                 //log
                 $this->error('DB 23000:' . $e->getLine() . $e->getCode() . $e->getMessage());
                 break;
             default:
                 //log
                 $this->error('DB error:' . $e->getLine() . $e->getCode() . $e->getMessage());
         }
     }
     //var_dump($products);
     //$this->info('XXX:'. $feed->location);
 }
开发者ID:shihqi,项目名称:fms,代码行数:76,代码来源:ParseFeed.php

示例4: google

 public function google(Request $request, $id)
 {
     // Generate Google FeedContent
     $feed = Feed::where('id', $id)->get();
     $total = Product::where('feed_id', $id)->count();
     if ($feed->isEmpty()) {
         return view(404);
     }
     if (Input::has('start')) {
         if (Input::has('limit')) {
             $products = Product::where('feed_id', $id)->skip($request->input('start'))->take($request->input('limit'))->get();
         } else {
             // 預設兩萬筆
             $products = Product::where('feed_id', $id)->skip($request->input('start'))->take(5000)->get();
         }
     } else {
         if (Input::has('limit')) {
             $products = Product::where('feed_id', $id)->take($request->input('limit'))->get();
         } else {
             // 預設兩萬筆
             $products = Product::where('feed_id', $id)->take(5000)->get();
         }
     }
     //$products = Product::where('feed_id', $id)->get();
     if ($request->input('action') == '1') {
         return response()->view('media.google', compact('products', 'feed', 'total'))->header('Content-Description', 'File Transfer')->header('Content-Disposition', 'attachment; filename=' . $feed->first()->description . '.xml')->header('Content-Transfer-Encoding', 'binary');
     } else {
         $outofstock = Product::onlyTrashed()->where('feed_id', $id)->get();
         return view('media.google', compact('products', 'feed', 'total', 'outofstock'));
     }
 }
开发者ID:shihqi,项目名称:fms,代码行数:31,代码来源:MediaController.php


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