Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jabrij93's avatar

Undefined variable $newBinds

I found the following error in my laravel.log,

[2023-05-15 22:52:36] local.ERROR: Undefined variable $newBinds (SQL: select * from [asset_timeslot] where exists (select * from [timeslots] where [asset_timeslot].[timeslot_id] = [timeslots].[id]) and [asset_id] = 2) {"userId":1,"exception":"[object] (Illuminate\Database\QueryException(code: 0): Undefined variable $newBinds (SQL: select * from [asset_timeslot] where exists (select * from [timeslots] where [asset_timeslot].[timeslot_id] = [timeslots].[id]) and [asset_id] = 2) at /home/jabs/workspace/ipbt/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760)

I tried to look for file other than /vendor/ and it refer to the following file code,

public function __invoke(Asset $asset, Activity $activity, Carbon $from, Carbon $to)
    {
        $timeslots = AssetTimeslot::query()
            ->with([
                'bookings' => fn ($query) => $query
                    ->with('activity', 'timeslots')
                    ->where('asset_id', $asset->id)
                    ->where('start_date', '>=', $from)
                    ->where('end_date', '<=', $to)
                    ->where('status', '!=', BookingStatus::CANCELLED->value),
                'timeslot.activity',
            ])
            ->whereHas('timeslot')
            ->where('asset_id', $asset->id)
            ->get();

        $period = CarbonPeriod::create($from, $to);
public static function run(...$params): mixed
    {
        $action = static::make();

        $method = method_exists($action, 'handle') ? 'handle' : '__invoke';

        return $action->{$method}(...$params);
    }
public function create(Request $request)
    {
        $availableTimeslots = [];

        if ($request->filled('asset_id')) {
            $asset = Asset::with(['activities', 'timeslots'])->find($request->query('asset_id'));
            $dateFrom = $request->date('from') ?? today();
            $dateTo = $request->date('to') ?? today();
            $activity = $asset->activities()->findOrFail($request->query('activity'));

            $availableTimeslots = GetAssetTimeslotByDate::run($asset, $activity, $dateFrom, $dateTo);
            // $availableTimeslots=format('%d %B %Y');
           
        }
     dd('debug timeslot');

       return Inertia::render('Booking/Create', [
            'assets' => $request->filled('activity') ?
                GetAssets::run($request->query(), [
                    'with' => [
                        'category',
                        'section',
                        'group',
                        'activities',
                        'facilities',
                        'additionalFacilities',
                        'supervisors',
                        'timeslots',
                    ],
                    'active' => true,
                    'paginate' => false,
                ])
                : [],
            'availableTimeslots' => $availableTimeslots,
            'bookings' => $request->filled('user_id') ?
                GetBookings::run($request->query(), [
                    'user' => $request->user(),
                ])->first()
                : null,
            'filters' => fn () => [
                'activityType' => $request->query('activityType', ''),
                'activity' => $request->query('activity', ''),
                'userId' => $request->query('user_id', ''),
            ],
        ]);

I tried to dd() in public function create() and it shows on the screen. However if I put it at the most bottom, I just get a white blank screen.

I've no idea how can I fix this ? Please help

0 likes
1 reply
LaryAI's avatar
Level 58

The error message "Undefined variable $newBinds" suggests that there is a missing variable in the SQL query. However, the code provided in the question does not contain any reference to $newBinds. Therefore, it is likely that the error is occurring in a different part of the codebase.

To debug this issue, you can try the following steps:

  1. Check the stack trace in the laravel.log file to see which file and line number the error is occurring on. This will give you a better idea of where to look for the issue.

  2. Check if there are any other SQL queries in the codebase that reference $newBinds. If so, make sure that the variable is defined before the query is executed.

  3. Check if there are any typos or syntax errors in the code that could be causing the issue. For example, a missing semicolon or a misspelled variable name.

  4. Try commenting out parts of the code to isolate the issue. For example, comment out the entire create() function and see if the error still occurs. If not, gradually uncomment sections of the code until you find the source of the issue.

Without more information about the codebase and the specific error message, it is difficult to provide a more specific solution.

Please or to participate in this conversation.