Support the ongoing development of Laravel.io →
Input Forms Validation

SOLVED

Accidentally had Laravel version 4.1.30 installed, installing 4.2.1 and copying Controllers, Views etc. to the new version solved my problem...

Hi everybody,

after having problems with validation and showing errors, I have set up this minimal/simple form with validation:

routes.php:

Route::resource('test', 'TestController');

TestController.php:

<?php

class TestController extends \BaseController {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function index()
	{
		//
		return 'test index';
	}


	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		//
		return View::make('form');
	}


	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		//
		$v = Validator::make(
			Input::all(),
			['test'=>'required']
		);

		if($v->passes())
		{
			return 'v passed';
		}
		else
		{
			return Redirect::to('test/create')->withErrors($v);
			//return $v->messages(); // this shows the errors...
		}
	}


	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}


	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
	}


	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		//
	}


	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		//
	}


}

form.blade.php:

{{ Form::open(['action'=>'TestController@store']) }}

{{ Form::text('test') }}

@if($errors->has('test'))
	{{ $errors->first('test') }}
@endif

{{ Form::submit('submit') }}

{{ Form::close() }}

When I submit the form without typing anything into the input, the validator fails, but I'm not able to show the error message...

What am I doing wrong?

Thanks in advance

EDIT:

I put those files into another laravel project directory for testing it there - and it's working in there! How's that possible?

Last updated 3 years 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.

© 2025 Laravel.io - All rights reserved.