Skip to content

Phone Integration for Developers

This page explains how phone developers can make their phone garage apps work with cd_garage.

If your phone script has a garage app, it should read vehicle status and garage data from the vehicle database table.

  • ESX usually uses owned_vehicles
  • QBCore/Qbox usually uses player_vehicles

Vehicle Status

Use the in_garage column to check where the vehicle is.

lua
in_garage = 0 -- Vehicle is on the streets
in_garage = 1 -- Vehicle is in a garage
in_garage = 2 -- Vehicle is in impound

Your phone script should use this value to show the correct vehicle status in the phone garage app.

Garage ID and Garage Label

The garage_id column is the garage’s unique ID.

Do not show garage_id directly to players.

Use this export to get the garage label from the garage ID:

lua
local garageId = '0ZDV-42KH-8OSX'
local garageLabel = exports.cd_garage:GetGarageLabelFromGarageId(garageId)

print(garageLabel)

-- Example output:
-- Legion Garage

This makes sure the phone app shows a clean garage name, such as Legion Garage, instead of a raw garage ID.

What Phone Scripts Should Do

  • Read vehicle data from owned_vehicles / player_vehicles.
  • Use in_garage for the vehicle status.
  • Use in_garage = 2 for impounded vehicles.
  • Do not show garage_id directly to players.
  • Use GetGarageLabelFromGarageId to show the garage name.

Example: Get Vehicles From Database

This example gets the player’s vehicles from the database, converts the garage ID into a garage label, and formats the data for a phone garage app.

Example Function
lua
function GetVehicles(source)
    local Player = QBCore.Functions.GetPlayer(source)
    if not Player then return end

    local vehicles = {}

    local result = MySQL.query.await('SELECT * FROM player_vehicles WHERE citizenid = ?', {
        Player.PlayerData.citizenid
    })

    if not result or not result[1] then
        return
    end

    for i = 1, #result do
        local v = result[i]
        local vehicleData = QBCore.Shared.Vehicles[v.vehicle]

        if vehicleData then
            local props = json.decode(v.mods or '{}')

            local state = 'Out On Streets'
            if v.in_garage == 1 then
                state = 'In Garage'
            elseif v.in_garage == 2 then
                state = 'In Impound'
            end

            local fullname = vehicleData.name
            if vehicleData.brand then
                fullname = vehicleData.brand .. ' ' .. vehicleData.name
            end

            vehicles[#vehicles + 1] = {
                fullname = fullname,
                brand = vehicleData.brand,
                model = vehicleData.name,
                plate = v.plate,
                garage = exports.cd_garage:GetGarageLabelFromGarageId(v.garage_id),
                state = state,
                fuel = props.fuelLevel,
                engine = props.engineHealth,
                body = props.bodyHealth
            }
        end
    end

    return vehicles
end
  • in_garage is used to show if the vehicle is out, garaged, or impounded.
  • GetGarageLabelFromGarageId is used so the phone app shows the garage name instead of the raw garage ID.
  • This example uses QBCore and player_vehicles, but the same idea can be used with ESX and owned_vehicles.

Useful Export

👉 View Get Garage Label From Garage ID Export →

Hello!