Php 使用maatweb将Excel工作表导入Laravel 5.1
我正在尝试学习如何将基本excel工作表导入laravel 5.1Php 使用maatweb将Excel工作表导入Laravel 5.1,php,mysql,excel,laravel-5.1,maatwebsite-excel,Php,Mysql,Excel,Laravel 5.1,Maatwebsite Excel,我正在尝试学习如何将基本excel工作表导入laravel 5.1 vname Vservice vphone vmobile test name test service test number 123232 test mobile 12344 我做了如下的函数 public function ImportVlist() { Excel::load('/import.xlsx', function($r
vname Vservice vphone vmobile
test name test service test number 123232 test mobile 12344
我做了如下的函数
public function ImportVlist()
{
Excel::load('/import.xlsx', function($reader)
{
$results = $reader->get();
foreach ($results as $key => $value) {
foreach ($value as $key => $value1) {
Vlist::create([
'vname'=>$value1->vname,
'vservice' => $value1->vservice,
'vphone' => $value1->vphone,
'vmobile' => $value1->vmobile
]);
}
}
})->get();
}
我走了一条路
Route::get('/vlist/import' , 'VlistsController@ImportVlist');
在索引中,我建立了以下链接
<li><a href="{{ action('VlistsController@ImportVlist') }}"> <span>Import Suppliers </span></a></li>
但是,当我单击“我接收未找到的页面”时,excel未导入mysql db中,操作的路由应定义如下:
Route::get('/vlist/import', array('as' => 'vlist.import', 'uses' => 'VlistsController@ImportVlist'));
此外,您还可以使用controller()
helper:
Route::controller('vlist', 'VlistsController', ['getImportVlist' => 'vlist.import']);
然后,该控制器内具有http方法前缀的所有方法将绑定到如下路由:
public function getImportVlist()
{
Excel::load('/import.xlsx', function($reader)
{
...
}
}
并且可以通过路由名称在视图中引用:
<li><a href="{{ route('vlist.import') }}"> <span>Import Suppliers </span></a></li>
这样,您就无需在synk中保留控制器和路由和视图:
<li><a href="{{ route('vlist.import') }}"> <span>Import Suppliers </span></a></li>
vlist.en.php
<?php
return [
...
'import' => 'Import Suppliers',
...
];
<?php
return [
...
'import' => 'Поставщики',
...
];
行动路线应定义如下:
Route::get('/vlist/import', array('as' => 'vlist.import', 'uses' => 'VlistsController@ImportVlist'));
此外,您还可以使用controller()
helper:
Route::controller('vlist', 'VlistsController', ['getImportVlist' => 'vlist.import']);
然后,该控制器内具有http方法前缀的所有方法将绑定到如下路由:
public function getImportVlist()
{
Excel::load('/import.xlsx', function($reader)
{
...
}
}
并且可以通过路由名称在视图中引用:
<li><a href="{{ route('vlist.import') }}"> <span>Import Suppliers </span></a></li>
这样,您就无需在synk中保留控制器和路由和视图:
<li><a href="{{ route('vlist.import') }}"> <span>Import Suppliers </span></a></li>
vlist.en.php
<?php
return [
...
'import' => 'Import Suppliers',
...
];
<?php
return [
...
'import' => 'Поставщики',
...
];
您是否已将autoloader与artisan重新编译php artisan dump autoload
或php artisan clear compiled
或类似的smth…composer dump autoloadwell,然后确保以下内容:1)您通过http://yourdomain/vlist/import
2)您的VlistsController
被放置在适当的命名空间中(如App\Http\Controllers
)在控制器实现脚本和routes.php
3)vlist.import
route未放置在某个带前缀的组(route::group(['prefix'=>'/some/path'],function(){…})
)中,或使用midleware阻止访问4)路由到方法在路由列表中(php artisan routes list
或smth)5)控制器方法返回正确的响应(如return view('vlist.import',[data=>$data]);
)好的,我已将路由更改为vlist.create,现在我收到的vlist变量未定义当我向vlist.create页面发送路由时,它与create函数冲突,当我路由到vlist.import时,它说找不到页面,我不知道在vlist.import中键入什么以及如何正确路由到它。您是否已与artisan重新编译autoloaderphp artisan dump autoload
或php artisan clear compiled
或类似的smth…composer dump autoloadwell,然后确保以下内容:1)您通过http://yourdomain/vlist/import
2)您的VlistsController
被放置在适当的命名空间中(如App\Http\Controllers
)在控制器实现脚本和routes.php
3)vlist.import
route未放置在某个带前缀的组(route::group(['prefix'=>'/some/path'],function(){…})
)中,或使用midleware阻止访问4)路由到方法在路由列表中(php artisan routes list
或smth)5)控制器方法返回正确的响应(如return view('vlist.import',[data=>$data]);
)好的,我已将路由更改为vlist.create,现在我收到的vlist变量未定义当我向vlist.create页面发送路由时,它与create函数冲突,当我路由到vlist.import时,它说找不到页面,我不知道在vlist.import中键入什么以及如何正确路由到它