当前位置: 首页 > news >正文

网站必须做ssl认证餐饮营销方案100例

网站必须做ssl认证,餐饮营销方案100例,一品威客网络兼职网,学做网站哪里学在Laravel中,可以使用maatwebsite/excel这个库来处理Excel文件的导入。 1.用命令行窗口打开项目根目录,使用 Composer 安装 maatwebsite/excel composer require maatwebsite/excel --ignore-platform-reqs 在你的config/app.php文件中注册服务提供者&…

在Laravel中,可以使用maatwebsite/excel这个库来处理Excel文件的导入。

1.用命令行窗口打开项目根目录,使用 Composer 安装 maatwebsite/excel

composer require maatwebsite/excel --ignore-platform-reqs

在你的config/app.php文件中注册服务提供者(可选)

'providers' => [// ...Maatwebsite\Excel\ExcelServiceProvider::class,
],

注册门面(Facade)(可选)

'aliases' => [// ...'Excel' => Maatwebsite\Excel\Facades\Excel::class,
],

 

2. 使用php artisan make:import命令创建一个新的导入类

php artisan make:import UsersImport --model=User

这将会生成一个新的Import类UsersImport,并且已经引入了你需要的User模型。

在生成的UsersImport类中,你需要定义collection方法来处理导入的数据集合,以及model方法来处理单个模型的导入。这里是一个简单的例子:

// app/Imports/UsersImport.phpnamespace App\Imports;use App\Models\User;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\Importable;class UsersImport implements ToModel
{use Importable;public function model(array $row){return new User(['name'     => $row[0],'email'    => $row[1],'password' => \Hash::make($row[2]),]);}
}

 3.在控制器中,添加一个方法来处理文件上传,并且调用导入。

// app/Http/Controllers/UserController.phpnamespace App\Http\Controllers;use App\Imports\UsersImport;
use Illuminate\Http\Request;class UserController extends Controller
{public function import(Request $request){$request->validate(['file' => 'required|file|mimes:xls,xlsx']);$file = $request->file('file');$import = new UsersImport();$import->import($file);return "Users imported successfully.";}
}

 4.定义路由

// routes/web.phpuse App\Http\Controllers\UserController;Route::post('/users/import', [UserController::class, 'import'])->name('users.import');

5.确保表单有enctype="multipart/form-data"属性,以便正确上传文件。

<form action="{{ route('users.import') }}" method="POST" enctype="multipart/form-data">@csrf<input type="file" name="file"><button type="submit">Import</button>
</form>

 

 

http://www.mmbaike.com/news/99512.html

相关文章:

  • 苹果做ppt模板下载网站有哪些关键词优化简易
  • 网站建设招标无锡下载百度导航app
  • 网页制作与设计书籍深度优化
  • 代理记账公司注册新手怎么入行seo
  • 南京电商网站建设公司数据分析师35岁以后怎么办
  • 深圳做h5网站seo外包优化公司
  • 国外有哪些网站平台怎么推广
  • 怎么建设像天猫的网站2022年最火文案
  • 学网站建设有什么用适合小学生摘抄的新闻2022年
  • 网站管理助手创建数据库网站建设规划书
  • 用sublime text做网站软文广告经典案例100字
  • 3000元做网站国际新闻视频
  • 石家庄网站建设接单知名的建站公司
  • 传智播客 网站开发seo优化公司哪家好
  • 企业网站建设教程视频百度地图推广怎么收费标准
  • 做茶叶网站的素材软文广告图片
  • 彩票娱乐网站建设开发怎么开网站
  • 网站建站授权模板下载短信广告投放软件
  • 北京正规网站建设公司seo权重优化
  • 做分类网站用什么cms北京搜索引擎优化seo专员
  • 阜阳网站是营销策略
  • 云服务器2008做网站国际新闻最新消息十条摘抄
  • 做淘宝好还是自建网站好网络营销推广难做吗
  • 18款未成年软件入口提升神马seo关键词自然排名
  • 国外的优秀网站河北网站建设案例
  • 群晖wordpress二级目录郑州百度快照优化
  • 电子商务网站规书网站关键词排名
  • 建行企业网站优化大师的使用方法
  • 做户型图的网站合肥优化排名推广
  • 做网站推广托管费用站长之家seo查找