/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::create(); $categories = Categories::where('parent_id', '>=', 0)->get(); $baseUrl = 'http://7xkn9n.com1.z0.glb.clouddn.com/img/'; $string = file_get_contents(__DIR__ . "/../data/products.json"); $products = json_decode($string, true); $cate_ids = []; foreach ($categories as $category) { $cate_ids[] = $category->id; } foreach ($products as $productData) { try { $name = $productData['meta']['title']; $content = ''; if (isset($productData['content'])) { $content = str_replace('<h2 class="title">百科词条</h2>', '', $productData['content']); } $klass = $productData['meta']['class']['text']; $category = Categories::where('name', $klass)->get(); $description = substr($content, 0, 100); $cid = $faker->randomElement($cate_ids); if ($category->count() == 1) { $cid = $category[0]->id; } $pieces = preg_split("/\\//i", $productData['meta']['image']); $product = Product::create(['name' => $name, 'slug' => $name, 'description' => $description, 'keywords' => $klass, 'cover' => $baseUrl . $pieces[count($pieces) - 1], 'category_id' => $cid, 'user_id' => 1]); $detailTopic = Topic::create(['title' => $name, 'slug' => $name, 'product_id' => $product->id, 'user_id' => 1, 'keywords' => $name, 'description' => $description, 'content' => $content, 'is_product_detail_topic' => true]); $product->detail_topic_id = $detailTopic->id; $product->save(); } catch (Exception $e) { throw $e; } } }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker::create(); $products = c2a(Product::lists('id')); $users = c2a(User::lists('id')); foreach (range(1, 20) as $index) { Topic::create(['title' => $faker->sentence(6), 'slug' => $faker->name, 'product_id' => $faker->randomElement($products), 'user_id' => $faker->randomElement($users), 'keywords' => $faker->sentence, 'description' => $faker->sentence(10), 'content' => $faker->sentence(100), 'page_view_count' => rand(10, 3059), 'vote_count' => rand(0, 199), 'reply_count' => rand(0, 100)]); } }
public function postCreateTopic() { $validator = new Validator(); $errors = $validator->isValid(Topic::$createTopicRules); if (sizeof($errors) > 0) { flash('errors', $errors); echo $this->blade->render('create-topic'); exit; } $data = ['title' => $_POST['title'], 'body' => strip_tags($_POST['body']), 'category_id' => $_POST['category'], 'user_id' => userLoggedIn()->id]; if (Topic::create($data)) { flash('success', ['new topic created successfully']); redirect('/'); } }
public function postSave(Request $request){ if($request->has('update')){ $topic = Topic::find($request->input('update')); $topic->teg_id = '1';//$request->input('teg'); $topic->title = $request->input('title'); $topic->description = $request->input('description'); $topic->content = $request->input('content'); //$topic->user_id = $this->user->id; $topic->save(); }else{ Topic::create([ 'teg_id' => $request->input('teg'), 'title' => $request->input('title'), 'description' => $request->input('description'), 'content' => $request->input('content'), 'user_id' => $this->user->id ]); } return redirect('topics')->with('message', 'Статья сохранена.'); }
public function run() { Topic::create(['id' => '1', 'name' => 'social', 'keyword1' => 'facebook', 'keyword2' => 'twitter', 'keyword3' => 'fb', 'keyword4' => 'instgram', 'keyword5' => 'social', 'keyword6' => 'follow', 'keyword7' => 'shared', 'keyword8' => 'network', 'keyword9' => 'weibo', 'keyword10' => 'google']); Topic::create(['id' => '2', 'name' => 'sports', 'keyword1' => 'baseball', 'keyword2' => 'basketball', 'keyword3' => 'tennis', 'keyword4' => 'ball', 'keyword5' => 'soccer', 'keyword6' => 'football', 'keyword7' => 'lakers', 'keyword8' => 'yankess', 'keyword9' => 'redsox', 'keyword10' => 'shoot']); Topic::create(['id' => '3', 'name' => 'computing', 'keyword1' => 'hadoop', 'keyword2' => 'cloud', 'keyword3' => 'spark', 'keyword4' => 'hbase', 'keyword5' => 'storm', 'keyword6' => 'aws', 'keyword7' => 'azure', 'keyword8' => 'hdinsight', 'keyword9' => 'using', 'keyword10' => 'shoot']); }