• javascript,  laravel,  mysql,  php

    Laravel-date format variable SQL query for API value

    given date value in string format , getting error in SQL query , so have to change it into date format in Laravel using Carbon function ( for date time )

    laravel controller sample work to get values in json [RestAPI]
    namespace App\Http\Controllers;
    use Illuminate\Http\Request;
    use App\Http\Resources\OrdersCollection;
    use Illuminate\Support\Facades\DB;
    use App\Http\Controllers\Controller;
    use app\Orders;
    use Response;
    use Carbon\Carbon;
    class OrdersController extends Controller
        public function index(Request $request)
            $fdate = $request->query('fdate');
            $gdate = $request->query('gdate');
            $users = DB::table('abctable')
                ->select(DB::raw('count(*) as count, city'))
             'abctable.entity_id', '=', 'xyztable.parent_id')
                ->whereBetween('abctable.created_at',[new Carbon($fdate),new Carbon($gdate)])
           return Response::json($users);

    Carbon function

    $users = DB::table(‘abctable’)
    ->select(DB::raw(‘count(*) as count, city’))
    ‘abctable.entity_id’, ‘=’, ‘xyztable.parent_id’)
    ->whereBetween(‘abctable.created_at’,[new Carbon($fdate),new Carbon($gdate)])