public function store(Request $request, $id = null) { $product = null; if ($id == null) { $product = \App\products::firstOrNew(['SKU' => $request->sku]); } else { $product = \App\products::find($id); } $image = null; $product->coverImageId = null; if ($request->hasFile('coverImage') && $request->file('coverImage')->isValid()) { $imageName = 'images/' . $request->file('coverImage')->getClientOriginalName(); $image = \App\images::firstOrNew(['url' => $imageName]); $image->title = $request->file('coverImage')->getClientOriginalName(); $image->save(); $request->file('coverImage')->move('images', $imageName); $product->coverImageId = $image->id; } $product->SKU = $request->sku; $product->price = $request->price; $product->currencyId = $request->currency; $product->publishDate = date('Y-m-d', strtotime($request->publishDate)); $product->cityId = $request->city; $product->vendorId = $request->vendor; $product->active = $request->Active; $product->save(); $text = \App\stringList::firstOrNew(['alias' => $request->alias]); $text->alias = $request->alias; $text->title = $request->title; $text->description = $request->description; $text->condition = $request->condition; $text->productId = $product->id; $text->languageId = 1; $text->save(); $count = 1; $product->images()->detach(); while (1) { $image = null; $fileName = 'image' . $count; if ($request->hasFile($fileName) && $request->file($fileName)->isValid()) { $imageName = 'images/' . $request->file($fileName)->getClientOriginalName(); $image = \App\images::firstOrNew(['url' => $imageName]); $image->title = $request->file($fileName)->getClientOriginalName(); $image->save(); $request->file($fileName)->move('images', $imageName); $product->images()->attach($image->id); $count++; } else { break; } } return $product->all()->load('text', 'currency', 'coverImage', 'city', 'vendor', 'images'); }
| and give it the controller to call when that URI is requested. | */ Route::get('/', function () { return view('homepage', ['showModal' => 'false', 'message' => '']); }); Route::post('/', function () { return view('homepage', ['showModal' => 'false', 'message' => '']); }); Route::get('/logout', function () { Auth::logout(); return Redirect::back(); }); Route: get('product/{alias}', function ($alias) { $text = \App\stringList::where('alias', $alias)->first(); if ($text != null) { return view('product', ['text' => $text]); } else { abort('404'); } }); Route::get('order/{package}', function ($package) { $showModal = 'true'; $message = ''; if (Auth::check()) { $lead = new App\leads(); $lead->fullName = Auth::user()->firstName . ' ' . Auth::user()->lastName; $lead->email = Auth::user()->email; $lead->package = str_replace('_', ' ', $package); $lead->save();