/** * Run the database seeds. * * @return void */ public function run() { $words = Word::all(); $categories = Category::all(); foreach ($words as $word) { $categoryIndex = mt_rand(0, count($categories) - 1); $word->categories()->save($categories[$categoryIndex]); } }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $category = Category::find($id); return view('category.show', ['category' => $category]); }