/** * 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 a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $words = Word::all(); return view('word.index', ['words' => $words]); }