我的Laravel学习之路之Laravel Forms 使用,illuminate/html包
来源:互联网 发布:virtualbox拖拽文件mac 编辑:程序博客网 时间:2024/05/22 08:02
首先声明,我使用的Laravel版本是Laravel Framework version 5.1.46 (LTS)
何为 illuminate/html,就是laravel为自己提供的一个Form表单工具
这个Form已经不再支持5.2以后的laravel了 ,用这个
https://packagist.org/packages/laravelcollective/html
使用前,直接安装composer require illuminate/htmlps:我的提示去权限问题,所以我切换到了普通用户
Using version ^5.0 for illuminate/html./composer.json has been updatedLoading composer repositories with package informationUpdating dependencies (including require-dev)Package operations: 1 install, 0 updates, 0 removals - Installing illuminate/html (v5.0.0): Downloading (100%) Package illuminate/html is abandoned, you should avoid using it. Use laravelcollective/html instead.Writing lock fileGenerating autoload files> Illuminate\Foundation\ComposerScripts::postUpdate> php artisan optimizeGenerating optimized class loader
出现以上,证明安装成功,然后你可以在vender目录下发现illuminate目录
然后我们打开config配置目录下的app.php文件,这是使用laravel自动加载的文件
在providers数组下增加
Illuminate\Html\HtmlServiceProvider::class,
然后在下面的aliases,学过linux知道这是系统别名,数组中添加
'Form' => Illuminate\Html\FormFacade::class,
在这里有个知识点.路由是按照由上倒下自动匹配的,举例:
试想一下,如果articles/create在{$id}这个的下面,create会作为参数的一个先执行,所以我们要移到上面来就可以了
Route::get('/article/create','ArticlesController@create');Route::get('/articles','ArticlesController@samples');Route::get('/article/{id}','ArticlesController@show');Route::post('/articles','ArticlesController@store');
然后我们在create方法中加载视图:return view('sites,create');
然后创建create.blade.php
在里面的占位区域添加如下:
@extends('app')@section('content')<div class="container"><h3>撰写新文章</h3>{!! Form::open(['url'=>'/articles']) !!}<div class="form-roups">{!! Form::label('name') !!}{!! Form::text('name',null,['class'=>'form-control']) !!}</div><div class="form-groups">{!! Form::label('content') !!}{!! Form::textarea('content',null,['class'=>'form-control']) !!}</div>{!! Form::submit('提交',['class'=>'btn btn-primary form-control']) !!}{!! Form::close() !!}</div>@stop
控制器中的代码为:
public function store(Request $request) { //知识点,如果我们要获得传递过来的其中指定值,可以使用下面两种方法 //$request['name']; 或者 $request->get('name'); //打印所有传递过来的值 //dd($request->all()); //第一步:接受post传递过来的数据 $input = $request->all(); //提示,如果需要存入当前时间字段,可使用Carbon::now(); 但是顶部要引入 use Carbon\Carbon; //比如文章发表时间可添加 $input['published_at'] = Carbon::now(); // 第二部:存入数据库 // laravel会帮我们自动过滤掉token Samples::create($input); // 第三部:重定向 return redirect('/articles'); }
阅读全文
0 0
- 我的Laravel学习之路之Laravel Forms 使用,illuminate/html包
- Laravel 5中使用 illuminate/html扩展
- 我的Laravel学习之路之模板继承
- 我的Laravel学习之路之环境配置
- 我的Laravel学习之路之Eloquent 入门
- 我的Laravel学习之路之表单验证 validation
- 我的Laravel学习之路之migration Laravel自带命令行数据库创建和管理工具
- 我的Laravel学习之路之我的Laravel学习之路之用户注册和登录 Auth
- laravel之dingoapi的使用
- Laravel基础-Illuminate所在位置
- 我的Laravel学习之路之模板加载,分配变量,简单路由
- 我的Laravel学习之路之实现简单Blog展示
- 我的Laravel学习之路之 模型方法queryScope 和字段设置setAttribute
- 我的Laravel学习之路之Route::resource和Form-Model-Binding,
- laravel 学习之第一章
- Laravel学习之
- Laravel使用之旅
- Laravel使用之旅
- js从服务器读取图片属性
- C++类的特性之继承
- laravel 学习笔记 —— 神奇的服务容器
- Internet Download Manager IDM下载器 免费领取7折 优惠劵
- Maven项目下的index.jsp文件报错
- 我的Laravel学习之路之Laravel Forms 使用,illuminate/html包
- React Native 混合开发 mac环境部署
- c#中Gridview控件写判断语句
- 面向对象和面向过程的区别和联系
- python3调用java的webService小程序
- elasticsearh集群布署与调试
- Qt调用插件
- TortoiseSVN的简单使用方法
- 一个简单的Twisted框架应用