private function getDescriptionsIdsArray() { $result = []; $categories = \App\Description::all(); foreach ($categories as $category) { $result[] = $category->id; } return $result; }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker\Factory::create('it_IT'); $projectsIds = 10; $projectIds = $this->getProjectsIdsArray(); for ($c = 0; $c <= $projectsIds; $c++) { //$idP = $faker->randomElements($projectIds, 1); $desk = Description::create(['step' => $faker->randomDigitNotNull, 'body' => $faker->sentence(), 'gallery_id' => 1, 'is_published' => 1, 'published_at' => $faker->dateTimeThisYear($max = 'now')]); $desk->projects()->sync($faker->randomElements($projectIds, 1)); } }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index($productId) { return Description::ofProduct($productId)->paginate(); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $this->validate($request, ['name' => 'required|unique:projects|max:255', 'rank' => 'required|integer', 'date_start' => 'date', 'date_end' => 'date', 'descriptions.id' => 'integer', 'descriptions.rank' => 'required|integer', 'descriptions.text' => 'required|max:500']); DB::beginTransaction(); $project = Project::find($id); if (!$project->save($request->only(['name', 'rank', 'date_start', 'date_end']))) { DB::rollback(); return redirect()->back()->withError('Could not save project'); } $descriptions = []; foreach ($request->get('descriptions') as $description) { if ($description['id']) { $descriptions[] = Description::find($description['id']); } else { $descriptions[] = new Description($description); } } if (!$project->descriptions()->saveMany($descriptions)) { DB::rollback(); return redirect()->back()->withError('Could not save description'); } DB::commit(); return redirect('admin'); }
public function index($productId, Request $request) { return Description::ofProduct($productId)->withKeyword($request->input('keyword'))->paginate(15); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // $this->validate($request, ['product_name' => 'required', 'category_id' => 'required']); $product = Product::find($id); $input = $request->all(); //dd($input); $product->fill($input); if (!$request->has('out_of_stock')) { $product->out_of_stock = 0; } if (!$request->has('active')) { $product->active = 0; } $product->save(); if ($request->hasFile('prod_image')) { $images = $request->file('prod_image'); // dd($images); foreach ($images as $image) { if ($image != null) { $image_name = $image->getClientOriginalName(); $image->move(public_path() . '/images/products/', $image_name); $status = $image->getError(); $newImage = Image::create(['image_name' => $image_name]); $product->images()->attach($newImage->id); } } } $description = Description::firstOrNew(array('product_id' => $id)); $description->description = $request->description; $description->save(); return redirect()->route('admin.product.index'); }
public static function getTutorialStepByProjectId($projID) { $steps = \App\Project::find($projID)->descriptions->sortBy('step'); foreach ($steps as $step) { $images = \App\Description::find($step->id)->images; $step->images = $images; $materials = \App\Description::find($step->id)->materials; $step->materials = $materials; } //dump($steps); return $steps; }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // $this->validate($request, ['product_name' => 'required', 'category_id' => 'required']); $product = Product::find($id); $input = $request->all(); //dd($input); $product->fill($input); if (!$request->has('out_of_stock')) { $product->out_of_stock = 0; } if (!$request->has('active')) { $product->active = 0; } $product->save(); $mrpInput = ['qty' => $request->mrp_qty, 'unit_id' => $request->mrp_unit_id, 'mrp' => $request->mrp_mrp]; $mrp = Mrp::firstOrNew(array('product_id' => $id)); $mrp->fill($mrpInput); $mrp->save(); if ($request->hasFile('prod_image')) { $images = $request->file('prod_image'); $files = $_FILES; foreach ($_FILES['prod_image']['tmp_name'] as $key => $tmp_name) { if (strlen($_FILES['prod_image']['name'][$key]) > 0) { $tmp_name = $_FILES['prod_image']['tmp_name'][$key]; $img_name = $_FILES['prod_image']['name'][$key]; $fileimage = Img::make($tmp_name); if ($fileimage->save(public_path() . '/images/products/' . $img_name)) { $newImage = Image::create(['image_name' => $img_name]); $product->images()->attach($newImage->id); } } } } //dd('images uploaded'); $description = Description::firstOrNew(array('product_id' => $id)); $description->description = $request->description; $description->save(); return redirect()->route('admin.product.index'); }