Support the ongoing development of Laravel.io →
Requests Input Database

Hi all, I've been working away on my app and to date I have been successful. I have stumbled across a problem when updating some information regarding "my customers"... Im getting a "NotFoundHttpException" which indicates the URL cant be found that needs to be "PATCHED / PUT". I can see the POST data successfully when it throws an error. Im thinking the {{ Form::open }} is wrong with the URL, would any one have an idea as to why it will not update?

Routes.php

/**
* Edit Specific Customer
*/
Route::get('/customers/{id}/edit', array(
	'as' => 'customers-edit',
	'uses' => 'CustomerController@edit'
));

/**
* Update Specific Customer
*/
Route::put('/customers/update', array(
	'uses' => 'CustomerController@update'
));

CustomerController.php

/**
* Edit Single Customer for View relation only id of customer
*/
public function edit($id) {
	//find customer
	$customer = Customer::find($id);
	//show the edit form
	return View::make('customers.edit')->with('customer', $customer);

}

/**
* Update Customer
*/ 
public function update() {

	$validation = Validator::make(Input::all(), 
		array(
	        'name' 		=> 'required|max:100',
	        'address'	=> 'required|min:3',
	        'city' 		=> 'required|min:3',
	        'postcode'  => 'required',
	        'phone'		=> 'required|min:11',
	        'mobile'	=> 'required|min:11',
	        'email'		=> 'required|email',
	        'contact'	=> 'required|max:100'
		)
	); //close validation

	//If validation fail send back the Input with errors
	if($validation->fails()) {
		//withInput keep the users info
		return Redirect::back()->withInput()->withErrors($validation->messages());
	} else {

		$user 	= Auth::user()->id;

		$customer = Input::get('id');
		$name = Input::get('name');
		$address =  Input::get('address');
		$city	= Input::get('city');
		$postcode = Input::get('postcode');
		$phone = Input::get('phone');
		$mobile =Input::get('mobile');
		$email =Input::get('email');
		$contact = Input::get('contact');


		Customer::where('id', $customer)->update(array(
			'name' 	  =>  $name,
			'address' =>  $address,
			'city'	=> $city,
			'postcode' => $postcode,
			'phone' => $phone,
			'mobile' => $mobile,
			'email' => $email,
			'contact' => $contact,
			'user_id'  => $user
		));


		return Redirect::route('all-customers')->with('message', 'You have successfully updated');
	}

}//close update

View edit.blade.php

@extends('layout.main')

@section('content')

<div class="container">

	<h1> Edit {{ $customer->name }} </h1>

	{{ Form::open(array('url' => 'customers-update', 'class' => 'form-horizontal')) }}

	<div class="form-group">

		<div class="col-sm-6">
			<label class="control-label" for="textinput">Customer Name</label>
			{{ Form::text('name', $customer->name, array('class' => 'form-control')) }}
			{{ $errors->first('name', '<span class=error>:message</span>') }}
		</div>


		<div class="col-sm-6">
			<label class="control-label" for="textinput">Address</label>
			{{ Form::text('address', $customer->address, array('class' => 'form-control' )) }}
			{{ $errors->first('address', '<span class=error>:message</span>') }}
		</div>

	</div>


	<!-- Text input-->
	<div class="form-group">

		<div class="col-sm-6">
			<label class="control-label" for="textinput">City</label>
			{{ Form::text('city', $customer->city, array('class' => 'form-control'')) }}
			{{ $errors->first('city', '<span class=error>:message</span>') }}
		</div>


		<div class="col-sm-6">
			<label class="control-label" for="textinput">Postcode</label>
			{{ Form::text('postcode', $customer->postcode, array('class' => 'form-control')) }}
			{{ $errors->first('postcode', '<span class=error>:message</span>') }}
		</div>

	</div>

	<div class="form-group">

		<div class="col-sm-6">
			<label class="control-label" for="textinput">Landline</label>
			{{ Form::text('phone', $customer->phone, array('class' => 'form-control')) }}
			{{ $errors->first('phone', '<span class=error>:message</span>') }}
		</div>


		<div class="col-sm-6">
			<label class="control-label" for="textinput">Mobile</label>
			{{ Form::text('mobile', $customer->mobile, array('class' => 'form-control')) }}
			{{ $errors->first('mobile', '<span class=error>:message</span>') }}
		</div>


	</div>

	<div class="form-group">

		<div class="col-sm-6">
			<label class="control-label" for="textinput">Email Address</label>
			{{ Form::text('email', $customer->email, array('class' => 'form-control')) }}
			{{ $errors->first('email', '<span class=error>:message</span>') }}
		</div>

		<div class="col-sm-6">
			<label class="control-label" for="textinput">Contact Name</label>
			{{ Form::text('contact', $customer->contact, array('class' => 'form-control')) }}
			{{ $errors->first('contact', '<span class=error>:message</span>') }}
		</div>

	</div>

            {{ Form::hidden('id', $customer->id) }}

	<div class="form-group">
		<div class="col-sm-12">
			{{ Form::submit('Update', array('class'=>'btn btn-large btn-primary btn-block'))}}
		</div>
	</div>


	{{ Form::close() }}
</div>
@stop

Would it be the URL within the form, im still manipulating the infromation inside the Form::open but not having any luck.

** I have updated the code and it now works after playing around with it. Removed 'as' out of the customers/update routes file. Removed the $id supplied to the update function and changed the update Customer eloquent query.**

Last updated 2 years ago.
0
Form::open(array('url' => 'customers-update', 'class' => 'form-horizontal', 'method' => 'put')

above code added an hidden input with name="_method" and value="put"

source: http://laravel.com/docs/html#opening-a-form (red box)

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

crippy crippy Joined 22 May 2014

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.