Support the ongoing development of Laravel.io →
Input Eloquent Architecture
Last updated 2 years ago.
0

Not sure if I classify as a seasoned L5 developer but a couple of thoughts.

Regarding these lines

$product = new Product($data);
$dir     = new Direction($data);
$map     = new MapDetail($data);

You should be injecting these objects into the method, not instantiating them within the controller action -> https://laracasts.com/series/whats-new-in-laravel-5/episodes/2

Regarding your private method "createImages" you would probably be better moving into a resusable event. In the example below I use something called the "repository pattern" a well documented approach and an example store method which includes an upload reads as follows:

public function store( AttachmentRequest $request )
{
	// Merge the name of the file being uploaded into the Input array so it can be saved to the database.
	\Input::merge(array('name'=> \Input::file('attachment')->getClientOriginalName() ) );
	// Use the repository method "processRequest" to create, populate, 
	// validate then save a new instance of the model.
	if ( $this->AttachmentRepository->processRequest( null, \Input::all() ) ) 
	{
		// Fire an event to move the uploaded file to permanent storage
		\Event::fire( new Upload( $this->AttachmentRepository ) );

		return \Response::json(['status' => 'true','message' => 'Successfully uploaded']);
	}
	else 
	{
		return \Response::json(['status' => 'false','message' => 'Something went wrong']);
	}
}

You will notice a "fire an event" which actually performs the upload after successful validation. Laravel events are well documented.

I could suggest plenty of other changes but Rome wasn't built in a day.

Good luck.

Last updated 8 years ago.
0

i will look into your suggestions, i know my code prob sucks, but im trying to learn, from a noob point of view and after reading more about repository patterns, yeah i see what you mean.

thank you!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

slayerfat slayerfat Joined 20 Mar 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.