在laravel中以json值返回视图

Posted

技术标签:

【中文标题】在laravel中以json值返回视图【英文标题】:Return view in json value in laravel 【发布时间】:2017-05-24 14:04:58 【问题描述】:
if($listing != null)   
    return \Response::json($listing);//return propertyees matching the search parameters
 else  
    return \Response::json(array(["message"=>"Sorry no properties found matching your search criteria. Please try again."]),200);           

以 json 格式返回视图

【问题讨论】:

我真的不知道您想要完成什么以及您已经尝试过什么。你能说得更具体点吗? 为了给您一个很好的答案,如果您还没有看过How to Ask,它可能会对我们有所帮助。如果您可以提供minimal reproducible example,它可能也很有用。 【参考方案1】:
if($listing != null)  
   return response()->json(['result' => $listing]);//return propertyees matching the search parameters
 else 
   return response()->json((["message"=>"Sorry no properties found matching your search criteria. Please try again."]),200);
   

【讨论】:

【参考方案2】:
if($listing != null)  
  return response()->json($listing);
 

【讨论】:

以上是关于在laravel中以json值返回视图的主要内容,如果未能解决你的问题,请参考以下文章