/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $inputs = Input::all(); $catalog = Catalog::find($id); $catalog->title = $inputs['title']; $catalog->description = $inputs['description']; $catalog->user_id = Auth::user()->id; $catalog->save(); $car = $catalog->car; if (empty($car)) { $car = new Car(); } else { $car = Car::find($catalog->car->id); } $car->brand = $inputs['brand']; $car->engine = $inputs['engine']; $car->make = $inputs['make']; $car->milage = $inputs['milage']; $car->type = $inputs['type']; $car->transmission = $inputs['transmission']; $car->status = $inputs['status']; $car->location = $inputs['location']; $car->price = $inputs['price']; $car->youtube = $inputs['youtube']; $car->main_pic = $inputs['main_pic']; $car->user_id = Auth::user()->id; $car->catalog_id = $catalog->id; $car->save(); $pictures = $inputs['pictures']; if (!File::isDirectory(user_photo_path() . $catalog->id . '/')) { File::makeDirectory(user_photo_path() . $catalog->id . '/', 0777, true, true); } if (isset($pictures) && count($pictures) > 0) { foreach ($pictures as $picture) { if ($picture != null) { $fileName = str_replace(' ', '_', strtolower($picture->getClientOriginalName())); $image = Image::make($picture->getRealPath()); $image->resize(1024, null, function ($constraint) { $constraint->aspectRatio(); })->save(user_photo_path() . $catalog->id . '/' . $fileName)->resize(750, null, function ($constraint) { $constraint->aspectRatio(); })->save(user_photo_path() . $catalog->id . '/' . '750-' . $fileName)->resize(500, null, function ($constraint) { $constraint->aspectRatio(); })->save(user_photo_path() . $catalog->id . '/' . '500-' . $fileName)->resize(250, null, function ($constraint) { $constraint->aspectRatio(); })->save(user_photo_path() . $catalog->id . '/' . '250-' . $fileName); $pic = new Pictures(); $pic->url = $fileName; $pic->user_id = Auth::user()->id; $pic->catalog_id = $catalog->id; $pic->type = 'catalog'; $pic->save(); } } } return Redirect::route('admin.catalog.index')->with('success', Lang::get('messages.catalog_updated')); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id) { $inputs = Input::all(); $catalog = Catalog::find($id); $catalog->title = $inputs['title']; $catalog->description = $inputs['description']; $catalog->user_id = Auth::user()->id; $catalog->save(); $project = $catalog->project; if (empty($project)) { $project = new Project(); } else { $project = Project::find($catalog->project->id); } $project->role = $inputs['role']; $project->customer = $inputs['customer']; $project->location = $inputs['location']; $project->start = $inputs['start-month'] . '-' . $inputs['start-year']; $project->end = isset($inputs['not-ended']) && $inputs['not-ended'] ? 'present' : $inputs['end-month'] . '-' . $inputs['end-year']; $project->main_pic = $inputs['main_pic']; $project->user_id = Auth::user()->id; $project->save(); $pictures = $inputs['pictures']; if (!File::isDirectory(user_photo_path() . $catalog->id . '/')) { File::makeDirectory(user_photo_path() . $catalog->id . '/', 0777, true, true); } if (isset($pictures) && count($pictures) > 0) { foreach ($pictures as $picture) { if ($picture != null) { $fileName = str_replace(' ', '_', $picture->getClientOriginalName()); $image = Image::make($picture->getRealPath()); $image->resize(1024, null, function ($constraint) { $constraint->aspectRatio(); })->save(user_photo_path() . $catalog->id . '/' . $fileName)->resize(750, null, function ($constraint) { $constraint->aspectRatio(); })->save(user_photo_path() . $catalog->id . '/' . '750-' . $fileName)->resize(500, null, function ($constraint) { $constraint->aspectRatio(); })->save(user_photo_path() . $catalog->id . '/' . '500-' . $fileName)->resize(250, null, function ($constraint) { $constraint->aspectRatio(); })->save(user_photo_path() . $catalog->id . '/' . '250-' . $fileName)->resize(75, null, function ($constraint) { $constraint->aspectRatio(); })->save(user_photo_path() . $catalog->id . '/' . '75-' . $fileName); $pic = new Pictures(); $pic->url = $fileName; $pic->user_id = Auth::user()->id; $pic->catalog_id = $catalog->id; $pic->type = 'catalog'; $pic->save(); } } } return Redirect::route('admin.catalog.index')->with('success', Lang::get('messages.catalog_updated')); }