public function store(MemberRequest $request) { $input = $request->all(); $member = new Member(); $member->name = $input['name']; $member->email = $input['email']; $member->phone = $input['phone']; if ($request->file()) { $image = $request->file('image'); $filename = $request->file('image')->getClientOriginalName(); $path = public_path('img/' . $filename); $size = '200,200'; Image::make($image->getRealPath())->resize(intval($size), null, function ($contstraint) { $contstraint->aspectRatio(); })->save($path); $member->image = 'img/' . $filename; } $member->save(); return redirect('member'); }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update($id, MemberRequest $request) { $member = Member::find($id); $oldOrder = $member->order; $newOrder = $request->input('order'); $type = $request->input('type'); /* Laravel can not handle using the request manager the validation of the size image that exceeds the configuration of php.in */ if ($this->imageHelper->fileImageSizeExceeded($request->file('image'))) { //Set the message and the error class Session::flash('message', 'The file image can not be greater than 2MB!'); Session::flash('alert-class', 'alert-danger'); return redirect()->back(); } //Fill this member with the new form information $member->fill($request->all()); //Getting the max permitted position $maxPosition = Member::where('type', $type)->count(); //If the admin informed a greater position, set the position as the maximum one if ($member->order > $maxPosition) { $member->order = $maxPosition; $newOrder = $maxPosition; } //Setting the right order $this->imageHelper->adjustUpdateOrder($type, $oldOrder, $newOrder, $member); //Checking if there was uploaded a image if ($request->file('image') != null) { //Delete the old member image from the filesystem File::delete($member->path); //Moves and sets the new uploaded image $this->imageHelper->uploadImage($request, $member); } $member->save(); //Sending the user to the accounts page return redirect()->route('member/index'); }
/** * Update the specified resource in storage. * * @param MemberRequest $request * @param $memberId * @return \Illuminate\Http\JsonResponse */ public function update(MemberRequest $request, $memberId) { (new Update())->run($request->all(), $memberId, 'member', true); return $this->response->noContent(); }