/** * Run the migrations. * * @return void */ public function up() { $classRooms = DB::select(DB::raw("select classrooms.id,classrooms.block from classrooms")); $array = []; foreach ($classRooms as $classRoom) { $array[] = Block::select()->where('name', '=', $classRoom->block)->get()->first()->id; } Schema::table('classrooms', function ($table) { $table->dropColumn('block'); $table->integer('block_id')->unsigned()->nullable(); $table->foreign('block_id')->references('id')->on('blocks'); }); $index = 0; $classRoom = Classroom::all(); foreach ($classRoom as $value) { $value->block_id = $array[$index]; $value->save(); $index++; } }
/** * Display a listing of the resource. * * @return Response */ public function index() { $classrooms = Classroom::all(); return view('classrooms.index', compact('classrooms')); }