首页 » 后端 » Laravel » 正文

Laravel 用法

发布者:站点默认
2019/09/24 浏览数(468) 分类:Laravel Laravel 用法已关闭评论

中文 faker

// config\app.php
'faker_locale'=>'zh_CN',

批量赋值不使用 fillable 属性

DB::table('articles')->truncate();
Article::unguard();
factory(Article::class, 10)->create();
Article::reguard();

软删除

# Trait // app/User.php
use Illuminate\Database\Eloquent\SoftDeletes;
class User extends Authenticatable
{
    use SoftDeletes;
}

# Migration
$table->softDeletes();
$table->dropSoftDeletes();

# 详见:https://learnku.com/docs/laravel/6.x/eloquent/5176#soft-deleting

关闭注册功能

# app/Http/Controllers/Auth/RegisterController.php
public function showRegistrationForm()
{
    return abort(404);
}
public function register(\Illuminate\Http\Request $request)
{
    return abort(404);
}

自定义错误显示信息

php artisan vendor:publish --tag=laravel-errors
// resources/lang/zh-CN.json
{
    "Unauthorized": "请先登录",
    "Forbidden": "禁止访问",
    "Not Found": "页面不存在",
    "Page Expired": "页面过期,请重试请求",
    "Too Many Requests": "访问人数过多,请稍候再来",
    "Server Error": "服务器程序错误",
    "Service Unavailable": "服务暂时不可用,请稍候再试"
}
点击返回顶部
  1. 留言
  2. 联系方式