public function store(QuestionRequest $request) { $q = Question::create($request->all()); $correct_answer_id; foreach ($request['options'] as $option) { $o = Option::create(['option' => $option['option'], 'question_id' => $q->id]); if ($request['correct_answer_id'] == $option['id']) { $correct_answer_id = $o->id; } } if ($request['correct_answer_id']) { CorrectAnswer::create(['question_id' => $q->id, 'option_id' => $correct_answer_id]); } return $q->toJson(); }
/** * Run the migrations. * * @return void */ public function up() { // Schema::create('options', function (Blueprint $table) { $table->increments('id'); $table->string('option'); $table->text('value'); $table->tinyInteger('serialized')->default(0); $table->timestamps(); $table->timestamp('published')->nullable(); $table->softDeletes(); }); Option::create(['option' => 'maintenance', 'value' => '0', 'published' => Carbon::create(2015, 00, 28, 15, 05, 29)]); Option::create(['option' => 'hero', 'value' => '0', 'published' => Carbon::create(2015, 00, 28, 15, 05, 29)]); Option::create(['option' => 'active', 'value' => 'home', 'published' => Carbon::create(2015, 00, 28, 15, 05, 29)]); Option::create(['option' => 'title', 'value' => 'Acclaim Events', 'published' => Carbon::create(2015, 00, 28, 15, 05, 29)]); Option::create(['option' => 'jumbotron', 'value' => '/images/networking.jpg', 'published' => Carbon::create(2015, 00, 28, 15, 05, 29)]); }
public function update_question($id, Request $request) { if (Auth::user()->type == 'teacher') { $input = $request->except('_token'); if ($input['type'] == 'descriptive') { $updated = DescriptiveQuestion::where(['id' => $id])->update(['question' => $input['question']]); if ($updated) { return response()->json(['stat' => 'success', 'message' => 'successfully updated question']); } else { return response()->json(['stat' => 'failed', 'message' => 'something wrong']); } } elseif ($input['type'] == 'multiple') { $updated_multiple = MultipleQuestion::where(['id' => $id])->update(['question' => $input['question'], 'answer' => $input['answer']]); if ($updated_multiple) { Option::where(['multiplequestion_id' => $id])->delete(); $count = count($request->input('option')); for ($i = 0; $i < $count; ++$i) { Option::create(['multiplequestion_id' => $id, 'option' => $request->input('option.' . $i)]); } return response()->json(['stat' => 'success', 'message' => 'successfully updated question']); } else { return response()->json(['stat' => 'failed', 'message' => 'something wrong']); } } else { return response()->json(['stat' => 'failed', 'message' => 'something wrong']); } } else { return response()->json(['stat' => 'failed', 'message' => 'not authorized']); } }
public function store(OptionRequest $request) { return Option::create($request->all()); }
/** * Execute the console command. * * @return mixed */ public function handle() { set_time_limit(0); ignore_user_abort(1); $english = Faker\Factory::create('en_GB'); $french = Faker\Factory::create('fr_FR'); $chinese = Faker\Factory::create('zh_CN'); $german = Faker\Factory::create('de_DE'); $spanish = Faker\Factory::create('es_ES'); $lorem = new Faker\Provider\Lorem($english); $langs = ['fr' => 'french', 'cn' => 'chinese', 'de' => 'german', 'es' => 'spanish', 'en' => 'english']; $shopId = $this->argument('shop'); $categories = (int) $this->argument('categories') + 1; $products = (int) $this->argument('products') + 1; // create 3 sets of options for color,size & material $data = ['Color' => ['Red', 'Green', 'Blue', 'Orange', 'Purple', 'Yellow'], 'Material' => ['Canvas', 'Glossy', 'Matt'], 'Size' => ['Xlarge', 'Large', 'Medium', 'Small', 'Xsmall']]; // build and create option foreach ($data as $key => $options) { $currentOptions = []; foreach ($langs as $lang => $label) { $currentOptions[$lang][$key] = $options; } $currentOptions['default'] = $currentOptions[$lang]; $option = Option::create($currentOptions); } for ($i = 1; $i < $categories; $i++) { // create a category; $categoryProducts = []; $category = new Category(); $category->shop_id = $shopId; $category->parent = 0; $category->slug = 'category-' . $i; $category->products = []; foreach ($langs as $code => $lang) { $data = ['name' => ${$lang}->name . ' ' . $i, 'content' => $lorem->sentence($nbWords = 6, $variableNbWords = true)]; $category->{$code} = $data; } $category->default = $data; $category->save(); // create products for ($x = 1; $x < $products; $x++) { // store $product = new Product(); $product->shop_id = $shopId; $product->slug = 'product-' . $x . '-category-' . $i; $product->sku = 'product-' . $x . '-category-' . $i; $product->categories = [$category->id]; $product->price = number_format(rand(50, 275), 2); $product->rrp = number_format($product->price * 1.2, 2); $product->salePrice = number_format($product->price * 0.8, 2); foreach ($langs as $code => $lang) { $data = ['name' => ${$lang}->name, 'content' => $lorem->sentence($nbWords = 200, $variableNbWords = true), 'excerpt' => $lorem->sentence($nbWords = 50, $variableNbWords = true)]; $product->{$code} = $data; } $product->default = $data; // save the product $product->save(); // register product with each new option $options = Option::all(); $newOptions = $toadd = []; foreach ($options as $option) { $optionProduct = OptionProduct::firstOrNew(['option_id' => $option->id]); $optionProduct->option_id = $option->id; $optionProduct_products = isset($optionProduct->products) ? $optionProduct->products : []; array_push($optionProduct_products, $product->id); $optionProduct->products = $optionProduct_products; $optionProduct->save(); // register option with this product $productOptions = isset($product->options) ? $product->options : []; array_push($productOptions, $option->id); $product->options = $productOptions; $product->option_values = []; $option_default = $option->default; $toadd[$option->id] = reset($option_default); $product->save(); } // we have the options lets add to the product $combo = []; for ($z = 0; $z < 3; $z++) { foreach ($toadd as $key => $value) { $combo[$z][$key] = array_rand($value, 1); } } $combo = array_map('unserialize', array_unique(array_map('serialize', $combo))); //$newOptions[$option->id][] = array_rand(reset($toadd), 1); $count = 0; foreach ($combo as $c) { $productOptionValues = $product->option_values; $new = ['sku' => $product->sku . '_' . $count++, 'price' => $product->price, 'options' => $c]; $productOptionValues[] = $new; $product->option_values = $productOptionValues; $product->save(); } // add this option to OPV table for quick filtering $povs = $product->option_values; foreach ($povs as $pov) { foreach ($pov['options'] as $keyz => $optionz) { $opv = OptionProductValue::where('filter', $keyz . '-' . $optionz)->first(); if (!$opv) { // insert first OptionProductValue::create(['filter' => $keyz . '-' . $optionz, 'products' => [$product->id]]); } else { // add to list $p = $opv->products; array_push($p, $product->id); $opv->products = array_unique($p); $opv->save(); } } } // add images $categoryProducts[] = $product->id; app('App\\Http\\Controllers\\Admin\\MediaController')->generateImages('products', $product->id, 'http://lorempixel.com/1600/900/'); $product->defaultImage = 'images/products/' . $product->id . '/large/image' . $product->id . '.jpg'; $product->save(); } $category->products = $categoryProducts; $category->save(); } }
/** * Add a new product option. * * @param string $id * * @return Redirect */ public function storeOption(Request $request, string $id) { $product = Product::find($id); $data = [$request->name => array_map('trim', explode(',', $request->options))]; $lang = $request->session()->get('language'); // build and create option $currentOptions[$lang][$request->name] = array_map('trim', explode(',', $request->options)); $currentOptions['default'] = $currentOptions[$lang]; $option = Option::create($currentOptions); // register product with this option $optionProduct = OptionProduct::firstOrNew(['option_id' => $option->id]); $optionProduct->option_id = $option->id; $optionProduct->products = [$product->id]; $optionProduct->save(); // register option with this product $productOptions = isset($product->options) ? $product->options : []; array_push($productOptions, $option->id); $product->options = $productOptions; // reset this products options $product->option_values = []; $product->save(); $request->session()->flash('success', trans('options.option') . ' ' . trans('crud.created')); return redirect()->back(); }
public function run() { DB::table("options")->delete(); Option::create(['question_id' => 1, 'option' => 'Floppy']); Option::create(['question_id' => 1, 'option' => 'Virus']); Option::create(['question_id' => 1, 'option' => 'Java']); Option::create(['question_id' => 1, 'option' => 'Monitor']); Option::create(['question_id' => 2, 'option' => '192.168.1.1']); Option::create(['question_id' => 2, 'option' => '192.168.111.1111']); Option::create(['question_id' => 2, 'option' => '192.168.900.1']); Option::create(['question_id' => 2, 'option' => '192.900.168.1']); Option::create(['question_id' => 3, 'option' => 'World Wide Web']); Option::create(['question_id' => 3, 'option' => 'Netscape Navigator']); Option::create(['question_id' => 3, 'option' => 'Internet Explorer']); Option::create(['question_id' => 3, 'option' => 'Safari']); Option::create(['question_id' => 4, 'option' => 'Application']); Option::create(['question_id' => 4, 'option' => 'Session']); Option::create(['question_id' => 4, 'option' => 'Cookie']); Option::create(['question_id' => 4, 'option' => 'QueryString']); Option::create(['question_id' => 5, 'option' => 'contact.website.info']); Option::create(['question_id' => 5, 'option' => 'contactwebsite.info']); Option::create(['question_id' => 5, 'option' => '*****@*****.**']); Option::create(['question_id' => 5, 'option' => 'contact@website@info']); Option::create(['question_id' => 6, 'option' => 'Hypertext Transfer Protocol']); Option::create(['question_id' => 6, 'option' => 'Hypertext Transfer Plotter']); Option::create(['question_id' => 6, 'option' => 'Head Tail Transfer Plot']); Option::create(['question_id' => 6, 'option' => 'Head Tail Transfer Protocol']); Option::create(['question_id' => 7, 'option' => 'Bit']); Option::create(['question_id' => 7, 'option' => 'Byte']); Option::create(['question_id' => 7, 'option' => 'Newton']); Option::create(['question_id' => 7, 'option' => 'Mega byte']); Option::create(['question_id' => 8, 'option' => 'TCS']); Option::create(['question_id' => 8, 'option' => 'IBM']); Option::create(['question_id' => 8, 'option' => 'Microsoft']); Option::create(['question_id' => 8, 'option' => 'Satyam']); Option::create(['question_id' => 9, 'option' => 'Jumber Verbose Mechanics']); Option::create(['question_id' => 9, 'option' => 'A part of IIS']); Option::create(['question_id' => 9, 'option' => 'Java Virtual Machine']); Option::create(['question_id' => 9, 'option' => '.Net Framework']); Option::create(['question_id' => 10, 'option' => 'Operating System']); Option::create(['question_id' => 10, 'option' => 'Storage Device']); Option::create(['question_id' => 10, 'option' => 'Processor']); Option::create(['question_id' => 10, 'option' => 'Output Device']); Option::create(['question_id' => 11, 'option' => 'Application Software']); Option::create(['question_id' => 11, 'option' => 'Motherboard']); Option::create(['question_id' => 11, 'option' => 'Operating System']); Option::create(['question_id' => 11, 'option' => 'RAM']); Option::create(['question_id' => 12, 'option' => 'Video']); Option::create(['question_id' => 12, 'option' => 'Sound']); Option::create(['question_id' => 12, 'option' => 'Image']); Option::create(['question_id' => 12, 'option' => 'Word Document']); Option::create(['question_id' => 13, 'option' => 'An Application software']); Option::create(['question_id' => 13, 'option' => 'A Process']); Option::create(['question_id' => 13, 'option' => 'A System Software']); Option::create(['question_id' => 13, 'option' => 'A Document']); Option::create(['question_id' => 14, 'option' => 'Low level language']); Option::create(['question_id' => 14, 'option' => 'Assembly language']); Option::create(['question_id' => 14, 'option' => 'High level language']); Option::create(['question_id' => 14, 'option' => 'Source code']); Option::create(['question_id' => 15, 'option' => 'File Transfer Protocol']); Option::create(['question_id' => 15, 'option' => 'File Transfer Program']); Option::create(['question_id' => 15, 'option' => 'File Thread Protocol']); Option::create(['question_id' => 15, 'option' => 'File Thread Program Option Four']); Option::create(['question_id' => 16, 'option' => 'Apple Inc.']); Option::create(['question_id' => 16, 'option' => 'Microsoft']); Option::create(['question_id' => 16, 'option' => 'Oracle Corporation']); Option::create(['question_id' => 16, 'option' => 'IBM']); Option::create(['question_id' => 17, 'option' => 'GWS']); Option::create(['question_id' => 17, 'option' => 'IIS 5.0']); Option::create(['question_id' => 17, 'option' => 'CERN httpd']); Option::create(['question_id' => 17, 'option' => 'nginx']); Option::create(['question_id' => 18, 'option' => 'Black Carbon Copy']); Option::create(['question_id' => 18, 'option' => 'Blind Carbon Copy']); Option::create(['question_id' => 18, 'option' => 'Business Computer Center']); Option::create(['question_id' => 18, 'option' => 'Business Computer Card']); Option::create(['question_id' => 19, 'option' => 'Application Software']); Option::create(['question_id' => 19, 'option' => 'System Software']); Option::create(['question_id' => 19, 'option' => 'Operating System']); Option::create(['question_id' => 19, 'option' => 'Scanner']); Option::create(['question_id' => 20, 'option' => 'Bill Board']); Option::create(['question_id' => 20, 'option' => 'James Gosling']); Option::create(['question_id' => 20, 'option' => 'Jame Smith']); Option::create(['question_id' => 20, 'option' => 'Sabeer Bhatia']); Option::create(['question_id' => 21, 'option' => 'Operating System']); Option::create(['question_id' => 21, 'option' => 'Web Browser']); Option::create(['question_id' => 21, 'option' => 'Microsoft Word']); Option::create(['question_id' => 21, 'option' => 'Microsoft Excel']); Option::create(['question_id' => 22, 'option' => 'MS Word and Spreadsheet']); Option::create(['question_id' => 22, 'option' => 'Transaction and Application']); Option::create(['question_id' => 22, 'option' => 'Microsoft and Mac OS']); Option::create(['question_id' => 22, 'option' => 'System and Application']); Option::create(['question_id' => 23, 'option' => '1000']); Option::create(['question_id' => 23, 'option' => '1001']); Option::create(['question_id' => 23, 'option' => '100']); Option::create(['question_id' => 23, 'option' => '1024']); Option::create(['question_id' => 24, 'option' => 'Information']); Option::create(['question_id' => 24, 'option' => 'Output']); Option::create(['question_id' => 24, 'option' => 'Data']); Option::create(['question_id' => 24, 'option' => 'Query']); Option::create(['question_id' => 25, 'option' => 'Internet Engineering Task Force']); Option::create(['question_id' => 25, 'option' => 'ICANN']); Option::create(['question_id' => 25, 'option' => 'Internet Architecture Board']); Option::create(['question_id' => 25, 'option' => 'No one owns it']); Option::create(['question_id' => 26, 'option' => 'Ctrl + P']); Option::create(['question_id' => 26, 'option' => 'Shift + P']); Option::create(['question_id' => 26, 'option' => 'Alt + P']); Option::create(['question_id' => 26, 'option' => 'Shift + PP']); Option::create(['question_id' => 27, 'option' => 'Application']); Option::create(['question_id' => 27, 'option' => 'Session']); Option::create(['question_id' => 27, 'option' => 'Cookie']); Option::create(['question_id' => 27, 'option' => 'QueryString']); Option::create(['question_id' => 28, 'option' => 'Compiler']); Option::create(['question_id' => 28, 'option' => 'Operating System']); Option::create(['question_id' => 28, 'option' => 'Input Device']); Option::create(['question_id' => 28, 'option' => 'Programming Language']); Option::create(['question_id' => 29, 'option' => 'Temporary file']); Option::create(['question_id' => 29, 'option' => 'Image file']); Option::create(['question_id' => 29, 'option' => 'Video file']); Option::create(['question_id' => 29, 'option' => 'Text file']); Option::create(['question_id' => 30, 'option' => 'Storing']); Option::create(['question_id' => 30, 'option' => 'Processing']); Option::create(['question_id' => 30, 'option' => 'Deletion']); Option::create(['question_id' => 30, 'option' => 'Organizing']); Option::create(['question_id' => 31, 'option' => 'Better Integrated Operating System']); Option::create(['question_id' => 31, 'option' => 'Basic Input Output System']); Option::create(['question_id' => 31, 'option' => 'Battery Integrated Operating Setup']); Option::create(['question_id' => 31, 'option' => 'Backup Input Output System']); Option::create(['question_id' => 32, 'option' => 'Least Area Network']); Option::create(['question_id' => 32, 'option' => 'Large Area Network']); Option::create(['question_id' => 32, 'option' => 'Local Area Network']); Option::create(['question_id' => 32, 'option' => 'Length Area Network']); Option::create(['question_id' => 33, 'option' => 'Satellite']); Option::create(['question_id' => 33, 'option' => 'Switch']); Option::create(['question_id' => 33, 'option' => 'Optical Fibre']); Option::create(['question_id' => 33, 'option' => 'Modem']); Option::create(['question_id' => 34, 'option' => 'Sytem file']); Option::create(['question_id' => 34, 'option' => 'MS Office document']); Option::create(['question_id' => 34, 'option' => 'Video file']); Option::create(['question_id' => 34, 'option' => 'Image file']); Option::create(['question_id' => 35, 'option' => 'Processor']); Option::create(['question_id' => 35, 'option' => 'Operating System']); Option::create(['question_id' => 35, 'option' => 'MS Word']); Option::create(['question_id' => 35, 'option' => 'Animation']); Option::create(['question_id' => 36, 'option' => 'DVD']); Option::create(['question_id' => 36, 'option' => 'Hard Disk']); Option::create(['question_id' => 36, 'option' => 'Floppy Disk']); Option::create(['question_id' => 36, 'option' => 'Mouse']); Option::create(['question_id' => 37, 'option' => 'GMail']); Option::create(['question_id' => 37, 'option' => 'Yahoo Mail']); Option::create(['question_id' => 37, 'option' => 'Hotmail']); Option::create(['question_id' => 37, 'option' => 'Rediff Mail']); Option::create(['question_id' => 38, 'option' => 'Laptops']); Option::create(['question_id' => 38, 'option' => 'Mainframe Computers']); Option::create(['question_id' => 38, 'option' => 'Mini Computers']); Option::create(['question_id' => 38, 'option' => 'Super Computers']); Option::create(['question_id' => 39, 'option' => 'Electronic track system']); Option::create(['question_id' => 39, 'option' => 'Part of register']); Option::create(['question_id' => 39, 'option' => 'Special memory']); Option::create(['question_id' => 39, 'option' => 'Part of a CPU']); Option::create(['question_id' => 40, 'option' => '5']); Option::create(['question_id' => 40, 'option' => '6']); Option::create(['question_id' => 40, 'option' => '7']); Option::create(['question_id' => 40, 'option' => '8']); Option::create(['question_id' => 41, 'option' => 'Apache']); Option::create(['question_id' => 41, 'option' => 'IIS']); Option::create(['question_id' => 41, 'option' => 'Jigsaw']); Option::create(['question_id' => 41, 'option' => 'Zaob']); Option::create(['question_id' => 42, 'option' => 'IBM 405']); Option::create(['question_id' => 42, 'option' => 'Zuse Z3']); Option::create(['question_id' => 42, 'option' => 'ENIAC']); Option::create(['question_id' => 42, 'option' => 'CSIRAC']); Option::create(['question_id' => 43, 'option' => 'Computed Gateway Interface']); Option::create(['question_id' => 43, 'option' => 'Compliant Gateway Interface']); Option::create(['question_id' => 43, 'option' => 'Case Gateway Interface']); Option::create(['question_id' => 43, 'option' => 'Common Gateway Interface']); Option::create(['question_id' => 44, 'option' => 'Oracle']); Option::create(['question_id' => 44, 'option' => 'AJAX']); Option::create(['question_id' => 44, 'option' => 'MySQL']); Option::create(['question_id' => 44, 'option' => 'SQL Server']); Option::create(['question_id' => 45, 'option' => 'Mouse']); Option::create(['question_id' => 45, 'option' => 'Hard Disk']); Option::create(['question_id' => 45, 'option' => 'Microprocessor']); Option::create(['question_id' => 45, 'option' => 'DVD']); Option::create(['question_id' => 46, 'option' => 'Param']); Option::create(['question_id' => 46, 'option' => 'Super 301']); Option::create(['question_id' => 46, 'option' => 'Compaq Presario']); Option::create(['question_id' => 46, 'option' => 'CRAY YMP']); Option::create(['question_id' => 47, 'option' => 'Internet']); Option::create(['question_id' => 47, 'option' => 'Linux']); Option::create(['question_id' => 47, 'option' => 'Unix']); Option::create(['question_id' => 47, 'option' => 'Windows']); Option::create(['question_id' => 48, 'option' => '10']); Option::create(['question_id' => 48, 'option' => '9']); Option::create(['question_id' => 48, 'option' => '0']); Option::create(['question_id' => 48, 'option' => '1']); Option::create(['question_id' => 49, 'option' => 'When x is less than one hundred']); Option::create(['question_id' => 49, 'option' => 'When x is greater than one hundred']); Option::create(['question_id' => 49, 'option' => 'When x is equal to one hundred']); Option::create(['question_id' => 49, 'option' => 'While it wishes']); Option::create(['question_id' => 50, 'option' => 'For']); Option::create(['question_id' => 50, 'option' => 'Do while']); Option::create(['question_id' => 50, 'option' => 'While']); Option::create(['question_id' => 50, 'option' => 'Repeat Until']); Option::create(['question_id' => 51, 'option' => 'Apple']); Option::create(['question_id' => 51, 'option' => 'Ball']); Option::create(['question_id' => 51, 'option' => 'Cat']); Option::create(['question_id' => 51, 'option' => 'Dog']); Option::create(['question_id' => 52, 'option' => 'Mouse']); Option::create(['question_id' => 52, 'option' => 'Tiger']); Option::create(['question_id' => 52, 'option' => 'Bear']); Option::create(['question_id' => 52, 'option' => 'Lion']); Option::create(['question_id' => 53, 'option' => 'Pink']); Option::create(['question_id' => 53, 'option' => 'Cool']); Option::create(['question_id' => 53, 'option' => 'Hot']); Option::create(['question_id' => 53, 'option' => 'Yellow']); Option::create(['question_id' => 54, 'option' => 'Red']); Option::create(['question_id' => 54, 'option' => 'Cheetah']); Option::create(['question_id' => 54, 'option' => 'Temporary']); Option::create(['question_id' => 54, 'option' => 'Digital']); Option::create(['question_id' => 55, 'option' => 'RAM']); Option::create(['question_id' => 55, 'option' => 'ECMAScript']); Option::create(['question_id' => 55, 'option' => 'Bother']); Option::create(['question_id' => 55, 'option' => 'Mother']); Option::create(['question_id' => 56, 'option' => 'Father']); Option::create(['question_id' => 56, 'option' => 'Zoo']); Option::create(['question_id' => 56, 'option' => 'PHP']); Option::create(['question_id' => 56, 'option' => 'Laravel']); }