我想運行查詢,將獲取給定日期之間的數據,但我沒有得到所需的結果。我有一個空白數組作爲輸出。Laravel數據庫查詢問題?
這是我在控制器代碼:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use DB;
use \Carbon\Carbon;
class reportController extends Controller
{
public $response;
public function contact_report(Request $request){
if($request->header('content-type')=='application/json'){
$from = \Carbon\Carbon::parse($request->from)->format('Y-m-d');
$to = \Carbon\Carbon::parse($request->to)->format('Y-m-d');
$cont_report = DB::connection('mysql_freesubs')->table('contact as c')
->select("c.fname", "c.lname","c.dob", "cl.value","c.doc")
->join("communication_link AS cl", "c.id", "=", "cl.cont_id")
->join("contact_communication AS cc", "cl.coco_id", "=", "cc.id")
->where("cc.type", "like","mobile%")
->whereBetween("c.doc", [new Carbon($from), new Carbon($to)])
->get();
$response = $cont_report;
}
else
$response = response()->json(['data'=>[],'error'=>1,'success'=>0,'error_msg'=>'not application/json', 'message'=>'Content type should be application/json']);
return $response;
}
}
謝謝@Rimon – SaMeEr