Support the ongoing development of Laravel.io →
posted 10 years ago
Input

I am trying to upload a news item that requires a image and a message

my form looks like

   <form action="/admin/nieuws/toevoegen" method="post" enctype="multipart/form-data">
		<div class="form-group">
			<input type="text" class="form-control" id="titel" name="titel" placeholder="Titel">
		</div>
	
	
		<div class="form-group">
			<label for="bericht">Het bericht</label>
			<textarea name="bericht" id="bericht" placeholder="Het nieuwsbericht">tester</textarea>
		</div>
		 
		<div class="form-group">
			<label for="exampleInputFile">Afbeelding </label>
		    {{ Form::file('file', array('multiple'=>true, 'id'=> 'file'));}}
			<p class="help-block">350px x 200px</p>
		</div>
		<button type="submit" class="btn btn-success">Toevoegen</button>
	{{ Form::close() }}

any my form handling looks like.

   public function postAddNieuws()
{
	$rules = array(
		'titel' => array('required', 'unique:nieuws,titel', 'min:7'),
		'bericht'    => array('required'),
		'file' => array('required','image')
	);
	$validation = Validator::make(Input::all(), $rules);
	if ($validation->fails())
	{
		return Redirect::to('admin/nieuws/toevoegen')
    	->withErrors($validation)
    	->withInput();
	}
	else 
	{
		return View::make('admin.nieuws.toevoegen');	
	}			
}

it dos not check the file and skips the image check what am i doing wrong?

Last updated 3 years ago.
0

files is plural in your validation rules, but singular when you declare the field in the view. Change your rule to 'file' instead of 'files'

Last updated 3 years ago.
0

stickman373 said:

files is plural in your validation rules, but singular when you declare the field in the view. Change your rule to 'file' instead of 'files'

i changed it still the same problem

Last updated 3 years ago.
0

If i fill in everything except a file i only get the file is required error if i fill in everyting with the file i get a error for every (title required, bericht required, file requiered)

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

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.

© 2025 Laravel.io - All rights reserved.