Laravel Builder could not be converted to string

3

I try to update two tables Meter and Order Installation , edit method receives the ID of the installation order, which is supposed to get the meter number, actually if I do dd ($ idmeter); the number is shown, but when I try to get the Meter with the find method by passing it the id, I get the following error.

  

[2017-05-24 17:47:56] local.INFO: installed order [2017-05-24   17:47:56] local.CRITICAL: Error apiControllerr 0 |   /Applications/MAMP/htdocs/juntaAgua/vendor/laravel/framework/src/Illuminate/Support/helpers.php   | Object of class Illuminate \ Database \ Query \ Builder could not be   converted to string

Driver

public function edit($id)
{
    $idmedidor = DB::table('Medidor')
        ->select(
            'Medidor.idmedidor')
        ->join('orden_instalacion', 'Medidor.orden_instalacion_idorden_instalacion', '=',
            'orden_instalacion.idorden_instalacion')
        ->where('orden_instalacion.idorden_instalacion', '=', $id)->get();

        try {
            DB::beginTransaction();

            $orden = OrdenInstalacion::find($id);
            $orden->estado = 1;
            $orden->fecha_instalacion = Carbon::now();
            $orden->update();
            Log::info("Orden instalada");

            $medidor = Medidor::find($idmedidor);
            $medidor->fecha_instalacion = Carbon::now();
            $medidor->estado = 1;
            $medidor->update();

            Log::info("medidor instalado");
            DB::commit();

        } catch (\Exception $e) {
            Log::critical("Error apiControllerr {$e->getCode()} | {$e->getFile()} |{$e->getMessage()} ");
            DB::rollback();
        }
    return redirect::to('api');
}
    
asked by jeancarlos733 25.05.2017 в 01:01
source

1 answer

2

Bearing in mind that you are looking for just one record, you should use the first() method instead of get() and get the respective property or field, in this case idmedidor :

$idmedidor = DB::table('Medidor')
    ->select('Medidor.idmedidor')
    ->join('orden_instalacion', 'Medidor.orden_instalacion_idorden_instalacion', '=', 'orden_instalacion.idorden_instalacion')
    ->where('orden_instalacion.idorden_instalacion', '=', $id)
    ->first()
    ->idmedidor;
    
answered by 25.05.2017 / 05:08
source