zoukankan      html  css  js  c++  java
  • laravel学习笔记(三)

    • 模型传值

    路由:

    Route::get('/posts/{post}','AppHttpControllersPostController@show');

    方法:

    public function show(Post $post){
        $isShowEdit = false;
        return view("post/show",compact,'isShowEdit','post'));
    }
    • CSRF保护

    laravel之伪造跨站请求保护CSRF实现机制:https://www.cnblogs.com/wanghaokun/p/10011668.html

    Laravel 下的伪造跨站请求保护

    {{csrf_field()}}
    <input type='hidden' name='_token' value='{{csrf_token}}' />

    X-CSRF-TOKEN

    <meta name="csrf-token" content="{{ csrf_token() }}">
    
    
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    • 调试方法

    dd:dump and die

    dd(Request::all())
    dd(request());
    dd(request('key'));
    • 数据库字段保护

    protected $guarded=[];                         //不可以注入的数据字段
    protected $fillable=['title','content'];      //可以注入的数据字段
    • 保存model

    
    
    //        $post = new Post();
    // $post->title = request('title');
    // $post->content = request('content');
    // $b = $post->save(); //true

    //
    $params = ['title'=>request('title'),'content'=>request('content')]; // Post::create($params); Post::create(request(['title','content'])); // dd(request()->all()); return(redirect('/posts'));
    •  验证错误提示

    参考地址:Http层-表单验证  https://laravel-china.org/docs/laravel/5.4/validation/1234

    eg:

    $this->validate(request(),[
        'title'     => 'required|string|max:100|min:5',
        'content'   => 'required|string|min:10'
    ]);

    验证提示汉化

    resourceslang 下en 的文件夹 复制在同一目录并改名为 zn

    把zn 中的 validation.php文件修改为对应汉化,https://laravel-china.org/articles/5840/validation-validation-in-laravel-returns-chinese-prompt

    修改config 目录下的app.php 文件,locale' => 'en' 改为 locale' => 'en'

    • 图片上传

    修改图片上传软链目录 config/filesystems.php 'default' => env('FILESYSTEM_DRIVER', 'public')

    storage:link Create a symbolic link from "public/storage" to "storage/app/public"

    php artisan storage:link
  • 相关阅读:
    cocos日记
    Android 开发经验
    vbs自学备份
    C# 如何在winform中嵌入Excel,内嵌Excel,word
    win7 64位在线编辑dsoframer控件的安装和使用配置
    C# 正则表达式 最全的验证类
    在 Range 对象中,Min (14)必须小于或等于 max (-1)。
    winform Form窗体和UserControl用户空间嵌入Panel容器并填充
    C# Winform防止闪频和再次运行
    Base64编码解码
  • 原文地址:https://www.cnblogs.com/wanghaokun/p/9999010.html
Copyright © 2011-2022 走看看