1
缺少論據2 照亮\數據庫\雄辯\型號::的setAttribute(),稱爲 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 2335 and definedLaravel缺少參數2
上面我試圖上傳一個CSV文件。
控制器:
public function postUpload()
{
if (Input::hasFile('file'))
{
DB::transaction(function()
{
// Clear out what we have written
DB::table('wc_program')->delete();
$csv = new CsvFile(Input::file('file')->getRealPath());
// Get the csv headers and move to the next line (the start of actual data)
$columns = $csv->getHeader();
$csv->next();
// Loop through the rows creating/saving a record for each
while($csv->valid())
{
$row = $csv->current();
$pc = new Programmes();
for($i=0; $i<count($columns); $i++)
{
$pc->$columns[$i] = $row[$i];
}
$pc->save();
$csv->next();
}
});
return Redirect::to('admin/programmes')->with('flash_success', 'Upload completed & new data inserted.');
}
然後,我有一個模型,那只是像很基本的,沒有什麼重大的這樣:
class Programmes extends Eloquent {
protected $guarded = array('id');
//public static $rules = array();
protected $table = 'wc_program_1';
public $timestamps = false;
}
和路線設置,如:
Route::get('admin/programmes/excelUpload','[email protected]');
Route::post('admin/programmes/doUpload', ['as' => 'admin.programmes.doUpload', 'uses' => '[email protected]']);