public function createGuestPost(Requests\Bins\CreateGuestBin $request) { $description = $request->has('description') && trim($request->description) != '' ? $request->description : null; $bin = Bin::create(['title' => $request->title, 'description' => $description, 'visibility' => $request->visibility]); $bin->versions()->sync($request->versions); $files = []; foreach ($request->file['name'] as $key => $value) { $files[$key]['name'] = $value; } foreach ($request->file['language'] as $key => $value) { $files[$key]['language'] = $value; } foreach ($request->file['code'] as $key => $value) { $files[$key]['code'] = $value; } foreach ($files as $item) { $type = Type::where('css_class', $item['language'])->first(); $bin->snippets()->create(['type_id' => $type->id, 'name' => $item['name'], 'code' => $item['code']]); } session()->flash('success', 'Bin created successfully!'); return redirect()->route('bin.code', $bin->getRouteKey()); }
public function createGuestPost(Requests\Bins\CreateGuestBin $request) { $recaptcha = new ReCaptcha(env('RECAPTCHA_SECRET')); $response = $recaptcha->verify($request->input('grc-response'), $_SERVER['REMOTE_ADDR']); if (!$response->isSuccess()) { session()->flash('error', 'You must prove you are human by completing the catpcha!'); return redirect()->route('bins.create'); } $description = $request->has('description') && trim($request->input('description')) != '' ? $request->input('description') : null; $bin = Bin::create(['title' => $request->input('title'), 'description' => $description, 'visibility' => $request->input('visibility')]); $bin->versions()->sync($request->input('versions')); $files = []; foreach ($request->input('name') as $key => $value) { $files[$key]['name'] = $value; } foreach ($request->input('language') as $key => $value) { $files[$key]['language'] = $value; } foreach ($request->input('code') as $key => $value) { $files[$key]['code'] = $value; } foreach ($files as $item) { $type = Type::where('css_class', $item['language'])->first(); $bin->snippets()->create(['type_id' => $type->id, 'name' => $item['name'], 'code' => $item['code']]); } session()->flash('success', 'Bin created successfully!'); return redirect()->route('bin.code', $bin->getRouteKey()); }