Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0

Anyone have any suggestions?

0

In my opinion is better the use of an ID.

0

Call your controller from your route like this:

Route::post('credit/update/{id}', 'CreditAppController@update');

Then in your controller do something like this:

public function update($id)
{
       $this->credit_app                               = CreditApp::find($id);
   
        foreach (Input::get() as $col => $val)
        {
               if (strlen(trim($val)) > 0)
               {
                      $this->credit_app->$col       = $val;
               }
         }
         $this->credt_app->save();
}
0
Solution

I think this is more likely a database modeling problem. To uniquely identified a row (and perform update), you will need an unique key. It could be id, the primary key if you would say, OR keys like, compound, concatenated, composite, foreign.

See: http://en.wikipedia.org/wiki/Unique_key

Supposed SSN (Social Security Number) is a unique identifier for any US citizen / resident. Then beside the key id, you can use SSN to pick up a particular person by their SSN. In this case, SSN is an alternate key beside primary key id.

Another possible key could be, last name combined with DOB (date of birth). Since it is nearly impossible to have the same DOB with the same last name at the same time, in that case, the 2 fields, dob and last name can be used to uniquely identify a user. Surely, the above example might not be 100% guarantee you pick the right row, therefore you get to design your database schema when it comes to these kind of situations.

For example,

To update using ssn instead of id

User::where('ssn', '=', '123-456-7890')->update(['name' => 'John Doe']);

If you seriously can't find any candidate keys to pick, then I think it's better for you to re-think of your table schema.

PS: Looks like I missed the important part, the model binding thing. :D As far as I am concerned, you might not be able to do it with Form::model() tho, just switch to Form::open() instead will do. (Correct me if I am wrong, since I don't use that method too often, I think that method is somehow overdoing things for me. I need more control than ease. :D )

Last updated 9 years ago.
0

Thank you awsp. The made it two lines into your comment and I realized how I just wasn't even thinking. And I've actually been using Form::open and using your suggestions, I believe it's all working now.

Thank you.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Yelldon yelldon Joined 2 Mar 2015

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.

© 2024 Laravel.io - All rights reserved.