缺少参数2 Illuminate \ Database \ Eloquent \ Model :: setAttribute(),调用 /vagrant/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php 在第2335行并定义
以上我尝试上传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','ProgrammesController@excelUpload');
Route::post('admin/programmes/doUpload', ['as' => 'admin.programmes.doUpload', 'uses' => 'ProgrammesController@postUpload']);
答案 0 :(得分:2)
代码段Illuminate\Database\Eloquent\Model::setAttribute()
需要两个参数,key及其值。在分配给列时,似乎缺少您的值。
我建议您在
附近调试代码$pc->$columns[$i] = $row[$i];
如果您发现有用的信息,请更新您的问题:)