2016-03-19 8 views
1

Ich habe erfolgreich Daten in der Datenbank gespeichert. Die Daten können jedoch nach dem Speichern nicht gefunden werden.Daten können nicht gerade in der Datenbank in Laravel gespeichert werden. 5.1

In JSON ist der Wert des Schlüsselobjekts ein leeres Array.

Meine Datenbank-Schema:

CREATE TABLE IF NOT EXISTS `bigdata_db`.`objects` (
    `object_id` CHAR(34) NOT NULL, 
    `object_lt_x` FLOAT NOT NULL, 
    `object_lt_y` FLOAT NOT NULL, 
    `object_width` FLOAT NOT NULL, 
    `object_height` FLOAT NOT NULL, 
    `image_id` CHAR(34) NOT NULL, 
    `type_id` CHAR(34) NOT NULL, 
    PRIMARY KEY (`object_id`), 
    INDEX `fk_objects_images1_idx` (`image_id` ASC), 
    INDEX `fk_objects_types1_idx` (`type_id` ASC), 
    CONSTRAINT `fk_objects_images1` 
    FOREIGN KEY (`image_id`) 
    REFERENCES `bigdata_db`.`images` (`image_id`) 
    ON DELETE CASCADE 
    ON UPDATE CASCADE, 
    CONSTRAINT `fk_objects_types1` 
    FOREIGN KEY (`type_id`) 
    REFERENCES `bigdata_db`.`types` (`type_id`) 
    ON DELETE CASCADE 
    ON UPDATE CASCADE); 

Mein Objektmodell:

protected $table = 'objects'; 
public $timestamps = false; 
protected $primaryKey = 'object_id'; 
public $incrementing = false; 
protected $fillable = ['object_id','object_lt_x', 'object_lt_y', 'object_width', 'object_height', 'image_id', 'type_id']; 

Speichern Sie die Daten in die Datenbank

$obj = new Object; 
$obj->object_id = $objectId; 
$obj->object_lt_x = $objX; 
$obj->object_lt_y = $objY; 
$obj->object_width = $objWidth; 
$obj->object_height = $objHeight; 
$obj->image_id = $imageId; 
$obj->type_id = $typeId; 
if ($obj->save()) { 
    $obj_id = $obj->object_id; 
    $object = DB::table('objects')->where('object_id',$objectId)->get(); 
    $success = array('status' => 1,'message' => $type_name.'标记成功!','obj_id' => $obj_id,'object' => $object); 
    return response()->json($success); 
} else { 
    $error = array('status' => 0,'message' => $type_name.'标记失败!'); 
    return response()->json($error); 
} 

Das Ergebnis ist:

Object {status: 1, message: "眼睛标记成功!", obj_id: "A7313004-3B7D-56F2-602F-FC81D4A8F04F", object: Array[0]} 
+0

zeigen Sie uns Ihre Datenbank-Schema – stjepano

+0

ich hinzufügen, das Datenbankschema, wie Sie verlangen (ich Englisch nicht gut) – LiberoFile

Antwort

0

Sieht für mich, dass Sie eine Bedingung für $obj->save() haben, aber Sie nie tatsächlich $obj->save(); aufgerufen, um den Eintrag zu speichern.

$obj = new Object; 
$obj->object_id = $objectId; 
$obj->object_lt_x = $objX; 
$obj->object_lt_y = $objY; 
$obj->object_width = $objWidth; 
$obj->object_height = $objHeight; 
$obj->image_id = $imageId; 
$obj->type_id = $typeId; 
$obj->save(); 

if ($obj->save()) { 
    $obj_id = $obj->object_id; 
    $object = DB::table('objects')->where('object_id',$objectId)->get(); 
    $success = array('status' => 1,'message' => $type_name.'标记成功!','obj_id' => $obj_id,'object' => $object); 
    return response()->json($success); 
} else { 
    $error = array('status' => 0,'message' => $type_name.'标记失败!'); 
    return response()->json($error); 

}

+0

Nein, wird es in 'if ($ obj-> speichern ausgeführt werden()) '. – user2094178

Verwandte Themen