2015-11-27 29 views
0

在我的一個laravel頁面中,我正在更新記錄。表單被綁定到模型,以及各個領域,不同的是那些我提出一個使用列表選擇填充從數據庫中選擇適當的更新:使用laravel的列表不能正常工作更新Laravel中的記錄

{{ Form::select('resume_id', $resume_lists) }}

我只是不知道爲什麼這些不會更新。他們正在從mySQL中提取適當的值。有任何想法嗎?

謝謝。

我有我的路線代碼,而不是在控制器

Route::get('application/edit/{id}', array('as' => 'application.edit', function($id) 
{ 
    $user = Auth::user(); 

    $company_lists = Company::where('user_id', '=', $user->id)->get()->lists('company', 'id'); 
    $resume_lists = Resume::where('user_id', '=', $user->id)->get()->lists('name', 'id'); //changed resume to name 
    $companies = Company::where('user_id', '=', Auth::user()->id)->get(); //just added 
    //$currentintdate=$application['followupBy']; ///// 
    Session::put('appid', $id); ///// 

    return View::make('application-edit', array('company_lists' => $company_lists), array('resume_lists' => $resume_lists)) 
     ->with('application', Application::find($id)); 
})); 
+0

你能告訴我們你的控制器的代碼嗎? – James

回答

0

試試這個:

$resume_lists = YourResumeModel::lists('title', 'id'); 

{{ Form::select('resume_id', $resume_lists) }} 

弗里斯特列是你的下拉 和下一列的文字是你的行ID

+0

我會試試這個謝謝你。創建記錄的相同代碼不會更新這些列的記錄......使用laravel/eloquent選擇的列。使用常規選擇這個工程,但我試圖與表單模式綁定使用Laravel。否則,我想我必須使用純SQL來填充選擇 – Nancymic

0

只是var轉儲控制器中的恢復列表數據,請確保它在控制器中可用,所以在初始化變量/數組後

return var_dump($resume_lists); // check if its valid array with id as key and label as value, if available, go view and do the same 
+0

這有助於知道。但是,它確實返回數組,並且它具有所有正確的值。它只是不會更新記錄。我想我錯過了一些愚蠢的事情,但是每當我使用_lists時它都會發生更新 – Nancymic

0

用途:$resume_lists = Resume::all()->where('user_id', '=', $user->id)->lists('name', 'id');

還是:$resume_lists = Resume::where('user_id', '=', $user->id)->lists('name', 'id')->toArray();

0

很好,我的記錄沒有更新,因爲我本來就有不可爲空列,我並沒有經過測試的同時任意值。我對此沒有任何錯誤,所以我不知道。