zoukankan      html  css  js  c++  java
  • Laravel Response

    Laravel 支持直接返回数组或者模型(或者集合),以下两种方式最终会被自动转为 json 响应:

    // 直接返回数组
    Route::get('/request-json-array', function(){
        $array = array('foo', 'bar');
        //this route should returns json response
        return $array;
    });
    
    // 或者返回模型/集合
    Route::get('/request-json-model', function(){
        //if 'User' is an eloquent model, this route should returns json response
        return User::all();
    });
    //响应json
    /*$data = [
    'errCode'=>0,
    'errMsg' =>'success',
    'data' => 'yxh',
    ];
    return response()->json($data);*/

    return Response::make($contents);
    return Response::make($contents, 200);
    return Response::json(array('key' => 'value'));
    return Response::json(array('key' => 'value'))
    ->setCallback(Input::get('callback'));
    return Response::download($filepath);
    return Response::download($filepath, $filename, $headers);
    // 创建一个回应且修改其头部信息的值
    $response = Response::make($contents, 200);
    $response->header('Content-Type', 'application/json');
    return $response;
    // 为回应附加上 cookie
    return Response::make($content)
    ->withCookie(Cookie::make('key', 'value'));

  • 相关阅读:
    vscode 基本知识以及如何配置 C++ 环境
    计算机视觉
    GitHub 大事件
    tf 2.0
    AI 公司与比赛
    Faster RCNN 学习与实现
    pycahrm安装说明
    python 并发之线程
    python 并发之进程
    python socketserver ftp上传功能
  • 原文地址:https://www.cnblogs.com/as3lib/p/14463157.html
Copyright © 2011-2022 走看看