laravel的那些坑

服务器是Nginx的 照着文档通过composer安装了一个非最新版本 (5.0)那版。

开始是看中文文档,死活安装不上,后来看了英文文档发现这个版本的安装说明是不同的 

按照这个命令 才能正确地安装

composer create-project laravel/laravel {directory} "~5.0.0" --prefer-dist

安装完成后发现首页也能跑了,但是其它路由都是404错误

发现原来需要给ngix配置增加一句话,其实英文文档下面就提到了,只是当时没仔细看文档。


location / { try_files $uri $uri/ /index.php?$query_string; }

我的完整的ngix配置文件

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

说明

Laravel 5 因为采用了另一套不同的架构, 而把 HTML 和 Form 类从核心里面移除.

如果还想继续使用这两个类的话, 可以使用以下方法:

添加到 composer.json

"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吧,毕竟教程也多。


数据迁移时,系统报错说是基表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.

Actions Handled By Resource Controller


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

转载于:https://my.oschina.net/lilugirl2005/blog/505619

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值