服务器是Nginx的 照着文档经过composer安装了一个非最新版本 (5.0)那版。 php
开始是看中文文档,死活安装不上,后来看了英文文档发现这个版本的安装说明是不一样的 css
按照这个命令 才能正确地安装 html
composer create-project laravel/laravel {directory} "~5.0.0" --prefer-dist
安装完成后发现首页也能跑了,可是其它路由都是404错误 nginx
发现原来须要给ngix配置增长一句话,其实英文文档下面就提到了,只是当时没仔细看文档。 laravel
location / { try_files $uri $uri/ /index.php?$query_string; }
个人完整的ngix配置文件 git
server { listen 80; server_name lv.aliyun lv.hihualang.com; index index.html index.htm index.php; root /alidata/www/lv/5/public; location ~ .*\.(php|php5)?$ { #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi.conf; } location / { try_files $uri $uri/ /index.php?$query_string; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 1h; } include /alidata/server/nginx/conf/rewrite/phpwind.conf; access_log /alidata/log/nginx/access/phpwind.log; }
Laravel 5 由于采用了另外一套不一样的架构, 而把 HTML 和 Form 类从核内心面移除. github
若是还想继续使用这两个类的话, 可使用如下方法: shell
"require": { "illuminate/html": "~5.0" },
composer update
更新完之后,打开 /config/app.php
providers数组下面添加
'Illuminate\Html\HtmlServiceProvider',
aliases数组下面添加
'Form' => 'Illuminate\Html\FormFacade', 'HTML' => 'Illuminate\Html\HtmlFacade'
{{Form::open()}} {{Form::close()}}
{!! Form::open() !!} {!! Form::close() !!}
后来发如今laravel5 下面用 html即便按照上面设置 仍是有问题, 根本搞不定,因此仍是放弃了在laravel5下面使用html和form的想法,干脆仍是先用laravel4吧,毕竟教程也多。 json
数据迁移时,系统报错说是基表migrations不存在, 这时候须要先执行命令生成migrations表 数组
$ php artisan migrate:install而后再执行
$ php artisan migrate
参考http://laravelbook.com/laravel-migrations-managing-databases/
Class 'Carbon' not found
只要在/app/config/app.php 文件下增长一条别名'aliases'
'Carbon' => 'Carbon\Carbon',
便可
controller里的 $this->beforeFilter on 的写法不起做用,
改用 only
例如
$this->beforeFilter('guest', ['only' => ['getLogin', 'getRegister']]);
缘由说是:The 'on' is actually for specifying a HTTP verb. Try this instead:
发如今laravel中写一个带参数的路由 但但愿把逻辑代码都写道对应的controller里是一件很难的事情,但有个技巧 你能够直接在代码区域new一个controller 返回这个controller的方法,就能够参数传入了
Route::get('{model}/lists', function ($model) { $className = 'App\Http\Controllers\\'.ucfirst($model).'Controller'; $obj = new $className; return $obj->lists(); });
后来发现其实不用这么作 laravel自带的restful方式,轻松建立带参数的路由 标准化增删该查 只要定义一行路由
Now we can register a resourceful route to the controller:
Route::resource('photo', 'PhotoController');
This single route declaration creates multiple routes to handle a variety of RESTful actions on the photo resource. Likewise, the generated controller will already have stubbed methods for each of these actions with notes informing you which URIs and verbs they handle.
Verb | Path | Action | Route Name |
---|---|---|---|
GET | /resource | index | resource.index |
GET | /resource/create | create | resource.create |
POST | /resource | store | resource.store |
GET | /resource/{resource} | show | resource.show |
GET | /resource/{resource}/edit | edit | resource.edit |
PUT/PATCH | /resource/{resource} | update | resource.update |
DELETE | /resource/{resource} | destroy | resource.destroy |
执行 php artisan generate:model xxx时报错
[InvalidArgumentException]
There are no commands defined in the "generate" namespace.
须要安装这个包 http://www.cnsecer.com/6696.html
执行代码的过程当中又发现 composer 报 zlib_decode(): data error
解决办法:执行 composer self-update 便可
发现用命令安装老是报错,直接放弃 ,去官网直接下载包
https://github.com/JeffreyWay/Laravel-4-Generators
能够经过命令下在一个完整包看看代码组织形式
$ git clone http://git.shiyanlou.com/shiyanlou/laravel-blog-2
替换 \vendor\composer\autoload_classmap.php 相关部分
拷贝 \vendor\way文件包
修改app.php
默认的时区须要改
‘timezone’ => ‘Asia/Shanghai’,//默认值嗯UTC