/** * Apply a photo to the referenced flyer. * Uses a dedicated form request called AddPhotoRequest. * * @param string $zip * @param string $street * @param AddPhotoRequest $request */ public function store($zip, $street, AddPhotoRequest $request) { // find our flyer $flyer = Flyer::locatedAt($zip, $street); // store the photo which will be just the UploadedFile instance $photo = $request->file('photo'); // we'll have a dedicated class like AddPhotoToFlyer and it will accept the flyer and the photo upload // and if that's its own instance, then we need to new it up and call a save method on it // this is an alternative way to do this. // if we wanted to treat this as a form object, you could even do your validation within that class rather than here, but in this case its so easy im just going to leave it in // and you would no longer need the AddPhotoRequest here. // we need to create this. we'll put it in app/Forms/AddPhotoToFlyer // we put this in Forms because we are treating this as a forms object // or i might have a more dedicated namespace like app/Flyers/AddPhotoToFlyer // or if you want you could put it in app/AddPhotoToFlyer and that would be okay too. thats what we will do here. (new AddPhotoToFlyer($flyer, $photo))->save(); // i like using a named constructor. that way i can new up a photo and pass in the columns essentially // or if i wanted to fetch these from (in this case) a file's request then its useful to use a named constructor. // we'll pass in the photo uploaded file. // built up our photo // $photo = Photo::fromFile($request->file('photo'))->upload(); //$photo = Photo::fromFile($request->file('photo')); // then we pass the photo to our flyer // But what about the process where we upload the file to the proper directory? // yes we persist it in the database. but we also need to move it to the folder and create the thumbnail. // located the current flyer. associate it with this flyer and save it. //Flyer::locatedAt($zip, $street)->addPhoto($photo); }
public function addPhoto($zip, $street, AddPhotoRequest $request) { $flyer = Flyer::locatedAt($zip, $street); $file = $request->file('file'); $photo = $this->makePhoto($file); $flyer->savePhoto($photo); }
/** * Store a new foto. * * @return \Illuminate\Http\Response */ public function store($zip, $street, AddPhotoRequest $request) { $flyer = Flyer::locatedAt($zip, $street); $photo = $request->file('photo'); //$photo = Photo::fromFile($request->file('file'))->upload(); $flyer->photos()->create(['path' => "/flyers/photos/{$name}"]); }
public function store($zip, $street, AddPhotoRequest $request) { $flyer = Flyer::locatedAt($zip, $street); $photo = $request->file('photo'); (new AddPhotoToFlyer($flyer, $photo))->save(); //$photo = Photo::fromFile($request->file('photo')); //Flyer::locatedAt($zip, $street)->addPhoto($photo); }
public function addPhoto($zip, $street, AddPhotoRequest $request) { $photo = Photo::fromFile($request->file('photo')); Flyer::locatedAt($zip, $street)->addPhoto($photo); // $this->validate($request,[ // 'photo' => 'required|mimes:jpg,jpeg,png,bmp' // ]); // // // if(! $this->userCreatedFlyer($request)) // { // return $this->unauthorized($request); // } // $photo = $this->makePhoto($request->file('photo')); // // Flyer::locatedAt($zip, $street)->addPhoto($photo); }
/** *Add a photo to flyer * * @param $postalCode * @param $street * @param AddPhotoRequest $request */ public function store($postalCode, $street, AddPhotoRequest $request) { $flyer = Flyer::locatedAt($postalCode, $street); $photo = $request->file('photo'); (new AddPhotoToFlyer($flyer, $photo))->save(); }
public function addPhoto($zip, $street, AddPhotoRequest $request) { $photo = Photo::fromFile($request->file('photo')); Flyer::locatedAt($zip, $street)->addPhoto($photo); }
/** * @param string $zip * @param string $name * @param AddPhotoRequest $request * * @return mixed */ public function addPhoto($zip, $name, AddPhotoRequest $request) { $event = Event::locatedAt($zip, $name); $photo = Event_Photo::fromFileWithEvent($request->file('photo'), $event)->upload(); $event->addPhoto($photo); }
public function addPhoto($zip, $street, AddPhotoRequest $request) { $flyer = Flyer::locatedAt($zip, $street); $photo = $request->file('photo'); (new AddPhotoToFlyer($flyer, $photo))->save(); }
public function store(AddPhotoRequest $request) { $photo = Photo::fromFile($request->file('file')); dd($photo); }
/** * Apply a photo to the referenced flyer * @param $zip * @param $street * @param AddPhotoRequest $request */ public function store($zip, $street, AddPhotoRequest $request) { $photo = Photo::fromFile($request->file('file')); //$photo = $this->makePhoto($request->file('file')); Flyer::locatedAt($zip, $street)->addPhotos($photo); }