Laravel使用心得

Laravel使用心得

1.session使用

laravel的session使用时,不要使用exit和die,否则session会为空。

2.ajax提交注意框架对post的CSRF保护

在头加上 <meta name="_token" content="{{csrf_token()}}"/> 可以解决ajax提交500的问题。
或者
ajax数据里添加一个 {"_token":'{{csrf_token()}}'} 提交项
或者
form表单添加一个 <input type="hidden" name="_token" value="{{csrf_token()}}"> 

3.打印SQL

DB::connection("mysql_2")->enableQueryLog();  // 开启查询日志
DB::connection("mysql_2")->table("jn_company_cost_electric")
    ->where($where)
    ->get();
$log = DB::connection("mysql_2")->getQueryLog();
dd($log);

 

posted @ 2018-07-10 16:29  OneNightStand  阅读(176)  评论(0编辑  收藏  举报