public function store(Request $request) { $competitor = new Competitor($request->all()); $competitor->save(); Flash::success('Competitor ' . $competitor->name . ' se ha registrado correctamente'); return view('register.competitor.create'); }
/** * Run the database seeds. * * @return void */ public function run() { $competitor = new Competitor(); $competitor->picture_url = "/img/competition/test-duvel.jpg"; $competitor->ip = "192.168.56.100"; $competitor->user_id = 1; $competitor->save(); }
public function postCompetition(Request $request) { $thisDate = Date::where('endDate', '>', Carbon::now())->where('startDate', '<=', Carbon::now())->first(); $thisCompetitions = Auth::user()->competitors; $hasParticipated = false; foreach ($thisCompetitions as $thisCompetition) { if ($thisCompetition->created_at >= $thisDate->startDate) { $hasParticipated = true; var_dump('participated: ' . $thisCompetition); } } if (!$hasParticipated) { $validator = Validator::make($request->all(), ['duvel' => 'required|image|mimes:jpeg']); if ($validator->fails()) { return redirect()->back()->withErrors($validator)->withInput(); } //check if image is valid if ($request->file('duvel')->isValid()) { $destinationPath = "img/competition/"; $extension = $request->file('duvel')->getClientOriginalExtension(); $fileName = rand(11111, 99999) . '.' . $extension; // renameing image random name //fullpath = path to picture + filename + extension $fullPath = $destinationPath . $fileName; $pic = $request->file('duvel'); //make a thumbnail for the same pic with a height of 100 $picSize = getimagesize($pic); $width = $picSize[0]; $height = $picSize[1]; $newHeight = 100; //change the width depending on the height of the pic $newWidth = $newHeight * ($width / $height); $image = imagecreatefromjpeg($pic); $thumbnail = imagecreatetruecolor($newWidth, $newHeight); //make the pic ($image) smaller and move it to $thumbnail $newImage = imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); //the path where to put the thumbnail $thumbnailPath = $destinationPath . 'thumbnail/' . $fileName; imagejpeg($thumbnail, $thumbnailPath); // uploading file to given path $pic->move($destinationPath, $fileName); //make the competitor object for the database $competitor = new Competitor(); $competitor->picture_url = '/' . $fullPath; $competitor->thumbnail = '/' . $thumbnailPath; $competitor->user_id = Auth::user()->id; $competitor->ip = $request->getClientIp(); $competitor->is_deleted = 0; $competitor->save(); return redirect()->route('otherCompetitors')->withErrors(["you've succesfully uploaded your picture. cheers!"]); } else { return redirect()->back()->withErrors('the image is not valid.'); } } else { return redirect()->route('otherCompetitors')->withErrors('you have already participated in our competition'); } }
public function store(CompetitorFormRequest $request) { $competitor = new Competitor(); $competitor->first_name = $request->get('first_name'); $competitor->last_name = $request->get('last_name'); $competitor->sex = $request->get('sex'); $competitor->birthday = $request->get('birthday'); $competitor->country_id = $request->get('country_id'); $competitor->club_id = $request->get('club_id'); $competitor->full_name = $request->get('last_name') . ' ' . $request->get('first_name'); $competitor->save(); $club = Club::where('id', '=', $request->get('club_id'))->firstOrFail(); $club->in_competition = 1; $club->save(); return redirect('admin/competitors')->with('status', 'Új versenyző felvétele kész.'); }
public function postCompetition(Request $request) { //check if image is valid if ($request->file('duvel')->isValid()) { $destinationPath = "img/competition/"; $extension = $request->file('duvel')->getClientOriginalExtension(); $fileName = rand(11111, 99999) . '.' . $extension; // renameing image //fullpath = path to picture + filename + extension $fullPath = $destinationPath . $fileName; $pic = $request->file('duvel'); //make a thumbnail for the same pic $picSize = getimagesize($pic); $width = $picSize[0]; $height = $picSize[1]; $newHeight = 100; //change the width depending on the height of the pic $newWidth = $newHeight * ($width / $height); $image = imagecreatefromjpeg($pic); $thumbnail = imagecreatetruecolor($newWidth, $newHeight); //make the pic ($image) smaller and move it to $thumbnail $newImage = imagecopyresampled($thumbnail, $image, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); var_dump($thumbnail); //the path where to put the thumbnail $thumbnailPath = $destinationPath . 'thumbnail/' . $fileName; imagejpeg($thumbnail, $thumbnailPath); // uploading file to given path $pic->move($destinationPath, $fileName); $competitor = new Competitor(); $competitor->picture_url = '/' . $fullPath; $competitor->thumbnail = '/' . $thumbnailPath; $competitor->user_id = Auth::user()->id; $competitor->save(); return redirect()->route('competition')->withSuccess("you've succesfully uploaded your picture. cheers!"); } }