public function run() { DB::table('comments')->truncate(); $faker = Faker\Factory::create('zh_TW'); foreach (range(1, 10) as $number) { App\Comment::create(['name' => $faker->name, 'email' => $faker->email, 'content' => $faker->paragraph, 'post_id' => rand(1, 10), 'created_at' => Carbon\Carbon::now()->addDays($number), 'updated_at' => Carbon\Carbon::now()->addDays($number)]); } }
public function run() { for ($i = 0; $i < 4; $i++) { App\Comment::create(['body' => 'This is comment ' . $i, 'article_id' => 4]); } for ($i = 4; $i < 6; $i++) { App\Comment::create(['body' => 'This is comment ' . $i, 'article_id' => 5]); } }
/** * Store a newly created comment. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $comment = new \App\Comment(); $comment->create(['user_id' => \Auth::user()->id, 'comment' => $request->comment, 'article_id' => $request['article_id']]); return redirect()->back(); }