php - Laravel 5 $request->input 与 Input::get

标签 php laravel laravel-5

只是想知道有什么区别:

$username = $request->input('username');

$username = Input::get('username');

最佳答案

没有区别,门面Input从request调用输入法。但是 Input::get 已被弃用,更喜欢 $request->input 而不是 Input::get

<?php

namespace Illuminate\Support\Facades;

/**
 * @see \Illuminate\Http\Request
 */
class Input extends Facade
{
    /** 
     * Get an item from the input data.
     *
     * This method is used for all request verbs (GET, POST, PUT, and DELETE)
     *
     * @param  string  $key
     * @param  mixed   $default
     * @return mixed
     */
    public static function get($key = null, $default = null)
    {   
        return static::$app['request']->input($key, $default);
    }   

    /** 
     * Get the registered name of the component.
     *
     * @return string
     */
    protected static function getFacadeAccessor()
    {   
        return 'request';
    }   
}

关于php - Laravel 5 $request->input 与 Input::get,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35316302/

相关文章:

php - laravel 中为 sql 查询安排的任务

php - Laravel 5 获取数据库前缀

php - 多个图像更新 laravel

PHP 转换数组键

php - 在两个 MySQL 表中存储值

javascript - Laravel 5.6 - 选中复选框时增加数字

php - 如何使用多个字段使用表单中的数据搜索 MySQL 数据库

php - 如何使用递归数组迭代器处理多维数组?

php - 如何访问 phpMyAdmin?

mysql - 使用 PHP 加速大型文本数据和文件的算法