php - dd($请求->全部());返回空数组

标签 php laravel

我正在尝试从 Laravel 5 应用程序上传一张照片以存储在 AWS 中。我正在使用 Postman REST 客户端进行测试。当我上传照片时,请求返回一个空数组。有谁知道为什么会这样?这是我的头像 Controller 的代码:

class AvatarController extends Controller
{

  public function __construct(AWS $aws)
  {
      $this->aws = $aws;
  }

/**
 * Store a new avatar for a user.
 * POST northstar.com/users/{id}/avatar
 */
  public function store(User $user, Request $request)
  {
    dd($request->all());
    // dd($request->file('photo'));

    $file = $request->file('photo');
    // $file = Request::file('photo');
    // $file = Input::file('photo');

    $v = Validator::make(
      $request->all(),
      ['photo' => 'required|image|mimes:jpeg,jpg|max:8000']
    );

    if($v->fails())
      return Response::json(['error' => $v->errors()]);         

    $filename = $this->aws->storeImage('avatars', $file);

    // Save filename to User model
    $user->avatar = $filename;
    $user->save();

    // Respond to user with success
    return response()->json('Photo uploaded!', 200);
  }
}

最佳答案

找到了答案 - 看起来我的 Postman 中的 header 存在问题。我有 Accept application/json 和 Content-Type application/json。一旦我删除了 Content-Type,一切就都解决了。谢谢!

关于php - dd($请求->全部());返回空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30334216/

相关文章:

php - 接收到的数据正确时,Doctrine2 hydration 不正确

php - 如何禁用缓存 100%

php - MySQL PHP : how to efficiently fetch previous X dates that include entries

php - 将 scandic 字母插入数据库时​​出错

laravel - 将额外的属性附加到 Laravel 数据透视表

PHP 数字格式作为输出

php - undefined variable : data (View: C:\xampp\htdocs\prolearning\resources\views\education.blade.php)

php - 在 Laravel 中执行节点脚本

php - Laravel - fatal error : Uncaught Error: Class 'Auth' not found

javascript - 如何使用 DashboardController 和 js 将 Id 从一个表获取到另一个表