Hi BlackPig,
I think you need to specify the fillable fields to your Model as follow:
protected $fillable = array('first_name', 'last_name'); //and another fields you need to fill with your Form inputs.
Hope it helps you.
Hi thanks, for the reply but that's not the issue - I have populated the $fillable array but it still doesn't save anything.
If I explicitly set the values:
$contact = new Contact;
$contact->first_name = Input::get( 'first_name' );
$contact->save();
the values are saved ok but if I pass the inputs then they don't:
$contact = new Contact;
$contact->save(Input::all());
as I understand it, Laravel/Eloquent should handle that ok.
I've learned and discovered a couple of things whilst trying to work out why my form data isn't being saved. I'll leave comments here that may help anyone else that has similar issues.
First up, my form data wasn't being saved with:
$contact = new Contact;
$contact->save(Input::all());
What I needed to do is:
$contact = new Contact;
$contact->fill(Input::all()->save());
I've seen various tuts/examples that use the first example without the ->fill() but I've not been able to get this to work.
The other thing that I've learned is model binding in the routes.php affects what is passed into the controller
In my routes.php I had:
Route::model('contacts', 'Contact');
Route::resource('contacts', 'ContactsController');
this would give me a a uri of contacts/4/edit to edit that contact record.
in my ContactsConroller
public function edit ( $id )
{
}
The $id parameter that is passed is NOT the $id of the contact but the actual Contact Object, so I could have:
public function edit ( Contact $contact )
{
return View::make('contacts.edit, compact('contact'));
}
If I don't have the Route::model binding set up in the routes.php then the $id parameter is the id value from the url
public function edit ( $id )
{
$contact = Contact::findOrFail($id);
return View::make('contacts.edit, compact('contact'));
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community