mercredi 15 avril 2015

Laravel 5 Request Class


Vote count:

0




In Laracasts, specifically Laravel 5 Fundamentals, Jeffrey mentioned about using the same Request Class for creating and updating a model. I have tried this but am getting an error:


here is my RequestClass



<?php namespace CRM\Http\Requests;

use CRM\Http\Requests\Request;

class ClientRequest extends Request {

/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public $rules = [
'company' => 'required|min:3',
'firstname' => 'required|min:3',
'lastname' => 'required|min:3',
'email' => 'required|email|unique:clients,email',
'phone' => 'required|min:6|phone|unique:clients,phone',
'address' => 'required|min:3'
];

public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
if($clients = $this->clients){

$this->rules['email'] .= ','.$clients ;
$this->rules['phone'] .= ','.$clients ;
}

return $this->rules;
}

public function messages()
{
return ['phone' => 'The phone number is not valid. Please confirm and try again.'];
}

}


It works fine when I create a new record, but throws an error when I update a record.


Here is the error message



SQLSTATE[42S22]: Column not found: 1054 Unknown column 'company:"BWA"' in 'where clause' (SQL: select count(*) as aggregate from `clients` where `email` = support@example.co.ke and `company:"BWA"` <> {"id":1 and `firstname:"richard"` = lastname:"keep" and `email:"support@example`.`co`.`ke"` = phone:"+27521341661" and `address:"test address"` = deleted_at:null and `created_at:"2015-04-15 08:46:45"` = updated_at:"2015-04-15 09:24:55"})


Here is my controller method



/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update(Client $client, ClientRequest $request)
{
$client->update($request->all());

return redirect('clients')->with('success', 'Client Updated Successfully');
}


Anyone with a clue what's going on here?



asked 1 min ago

Richie

425






Laravel 5 Request Class

Aucun commentaire:

Enregistrer un commentaire