代码之家  ›  专栏  ›  技术社区  ›  abu abu

laravelapi输出中的包装器

  •  0
  • abu abu  · 技术社区  · 6 年前

    "id": 1,
    "employee_id": 1,
    "text": "good",
    "employee": "Jamal"
    

    我的问题如下

    return $company
                ->employee()
                ->with('motorcycle', 'children')
                ->join('shop', function ($join) {
                    $join->on('shop.shop_id', '=', 'attendence.shop_id');
                    $join->on('shop.employee_id', '=', 'residence.employee_id');
                })
                ->get();
    

    我想得到如下输出

    "company": {
         "id": 1,
         "employee_id": 1,
         "text": "good",
         "employee": "Jamal"
    }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   Arman Hakim Sagar    6 年前

    这是我的api.php

    Route::get('articles', function() {
    
        $articles = article::all();
            if(count($articles) == 0){
               $feedback = [
                  'status'     => "error",
                  'message'    => "data not found",
                  'company'    => null
               ]; 
    
            }else{
                $articles = [
                   'status'     => "success",
                   'message'    => "data found",
                   'company'    => $articles
                ]; 
            }
    
        return $articles;
    });