我在我的数据库中有很多广告,我想从主题中选择一个我尝试但我得到一个空的回报
public function index()
{
# code...
// $Ads = ads::all();
// return $this->sendResponse($Ads->toArray(), 'Ads read succesfully');
$column = 'name'; // This is the name of the column you wish to search
$Ads = ads::where($column)->first();
return response()->json(['success'=> true,'ads'=>$Ads, 'message'=> 'Ads read succesfully']);
}
这就是我在帖子里得到的:
{“success”:true,“ads”:null,“message”:“成功阅读”}
在挖掘之前有一些事情需要注意:
考虑到上述说明,以下是适用于您的代码:
public function index(\Illuminate\Http\Request $request)
{
# code...
$column = 'name'; // This is the name of the column you wish to search
$columnValue = $request->input('name');// This is the value of the column you wish to search
$Ads = Ad::where($column, $columnValue)->first();
return response()->json(['success'=> true,'ads'=>$Ads, 'message'=> 'Ads read succesfully']);
}