Support the ongoing development of Laravel.io →
Database Eloquent Forms
Last updated 1 year ago.
0

you need a table image_types

id	type
1 	'small'
2	'big'

your images table

id	image_type_id	user_id	path
1	1				1		'smile.gif'
2	2				1		'woot.gif'

somewhere in your User model

public function images() {
	return $this->hasMany( 'Image' );
}

also you need to create the model file for Image, but at this point you only need the class declaration and $table variable, nothing more

class Image extends Eloquent {
	protected $table = 'images';
}

then for edition, i would do something like this (for creation is someting similar, you only need to get the all the image types ids from the image_types table)

@foreach( $user->images as $image )
	<!-- retrieve the uploaded image for displaying purposes -->
	{{ HTML::image( 'images/' . $image->path ) }
	<!-- bring a input to overwrite the uploaded image -->
	{{ Input::file( 'image-' . $image->image_type_id ) }}
@endforeach

then in your validation logic, according to the $image->image_type_id value you will know specifically what type of image it is, small or big, so the validation is just to trigger the correct validation code

note that the name field would be like this: image-1 and image-2

Last updated 1 year ago.
0

I thought about this option as well. This option seems it will require to be manually assignment of the image type id. This really isn't a full fledged dynamic CMS. I have multiple forms that use images table in the database. Each form will have different image requirements. The first example I gave has a small and large input field name. The next form will possibly have different names. Do you think this is still the best way to go?

Last updated 1 year ago.
0

is there a Laravel(ish) way to handle add multiple images in the edit/create forms? For example, how would you add an extra image, remove an image. This would all be done in Javascript of course.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.