public function postUpdate(GathersPostRequest $request)
 {
     $gather = Gather::find($request->id);
     $gather->name = $request->name;
     $gather->category_id = $request->category_id;
     $gather->code = $request->code;
     $gather->description = $request->description;
     $gather->save();
     foreach ($request->detail as $key => $value) {
         if ($value) {
             $detail = Detail::firstOrCreate(['gather_id' => $gather->id, 'item_id' => $key]);
             $detail->content = $value;
             $detail->save();
         }
     }
     return redirect()->to("gathers");
 }
Beispiel #2
0
 public function getAutoHomeCategories()
 {
     set_time_limit(0);
     $snoopy = new Snoopy();
     $url = "http://car.autohome.com.cn/baoyang/list_1_33_0_0_0.html";
     //构造抓取URL
     $snoopy->fetch($url);
     preg_match('/id="frame_tree"[\\s\\S]+?<ul>[\\s\\S]+?<\\/ul>/', $snoopy->results, $match);
     print_r($match);
     die;
     $snoopy->results = $match[0];
     preg_match_all('/id="brand_.+?>(\\w+)\\(/', $snoopy->results, $match);
     if (isset($match[0]) && !empty($match[0])) {
         $engines_match = $match[0];
         foreach ($engines_match as $prg_str) {
             preg_match_all('/href="(.+?)"/', $prg_str, $match);
             $all_urls = !empty($all_urls) ? array_merge($all_urls, $match[1]) : $match[1];
         }
     }
     if (!empty($all_urls)) {
         foreach ($all_urls as $url) {
             Detail::firstOrCreate(['autohome_url' => $url, 'brand_id' => $brand->id]);
         }
     }
     echo $brand->name . '-end-<br>';
 }