Laravel 小技巧
1 基本函数
return redirect(地址)
在route中设置重定向.
2 定义全局自定义函数
- 创建app/Utils/Utils.php,里面直接放方法
修改项目 composer.json
"autoload": { ... "files": [ "app/Utils/Utils.php" ] ... },
命令行运行
composer dump-autoload
,ok
3 Blade显示数据为字符串
var cases = {!!$cases!!};
alert();
//页面显示
var cases = [{"id":62,"created_at":"2015-11-10 04:38:46","updated_at":"2015-11-10 04:38:46","title":"4353","subhead":"534543","address":"534534","description":"","type":1,"logo":"","post_at":"0000-00-00 00:00:00","deleted_at":null}];
//alert([{"id":62,"created_at":"2015-11-10 04:38:46","updated_at":"2015-11-10 04:38:46","title":"4353","subhead":"534543","address":"534534","description":"","type":1,"logo":"","post_at":"0000-00-00 00:00:00","deleted_at":null}]);
4 Request替换/新增input
新增
$request->merge([key=>value]);
替换
$request->replace([key=>value]);