We're looking to store real estate information from a proprietary server (we're using PHRETS to retrieve the data and MySQL to store it). The old code is procedural and uses arrays, but I figured instead of writing our own objects, it would be best to use Eloquent ORM and let Laravel do the heavy lifting.
The datastream's structure is repeatable for every real estate property it sends, but the data will simply withhold information that it doesn't contain, (e.g. $property['AgentDetails']['Position'] may not be sent entirely if it doesn't exist on their end).
The other caveat is that some of the data is received in multidimensional arrays that currently need to be looped on and stored in separate, normalized tables (propertyAddress, propertyAgentDetails, propertyPhotos, etc.). This means the data may be sent as $property['AgentDetails'][0] ... $property['AgentDetails'][2] as it contains multiple listing agents or $property['AgentDetails'] if there is one listing agent.
We then have to retrieve this data with massive joins on the property ID.
I'm looking to setup a Laravel model and controller to do the heavy lifting and handle this datastream (insert if it doesn't exist, update if it does) where the simplified structure resembles this,
array(#) {
["@attributes"]=>
array(2) {
["ID"]=>
string(7) "444444"
["LastUpdated"]=>
string(29) "Fri, 13 Jul 2018 17:18:20 GMT"
}
["ListingID"]=>
string(7) "3333333"
["AgentDetails"]=>
array(6) {
["@attributes"]=>
array(1) {
["ID"]=>
string(7) "2222222"
}
["Name"]=>
string(14) "AGENT NAME"
["Websites"]=>
array(1) {
["Website"]=>
string(26) "http://example.com"
}
["Office"]=>
array(7) {
["@attributes"]=>
array(1) {
["ID"]=>
string(5) "111111"
}
["Name"]=>
string(27) "REALTY CO"
["Address"]=>
array(5) {
["StreetAddress"]=>
string(19) "59 main st. west"
["AddressLine1"]=>
string(19) "59 main st. west"
["City"]=>
string(7) "city"
["Province"]=>
string(2) "province"
["PostalCode"]=>
string(6) "H0H0H0"
}
["Phones"]=>
array(1) {
["Phone"]=>
array(1) {
[0]=>
string(14) "(555) 555-5555"
}
}
["Websites"]=>
array(1) {
["Website"]=>
string(30) "http://www.example.com"
}
["OrganizationType"]=>
string(4) "Firm"
["Franchisor"]=>
string(11) "Independent"
}
}
["Building"]=>
array(7) {
["CoolingType"]=>
string(15) "Air Conditioned"
["FireplacePresent"]=>
string(5) "False"
["FireProtection"]=>
string(21) "Full Sprinkler System"
["HeatingType"]=>
string(29) "Baseboard heaters, Forced air"
["SizeInterior"]=>
string(10) "15000.0000"
["TotalFinishedArea"]=>
string(10) "15000 sqft"
["UtilityWater"]=>
string(15) "Municipal water"
}
["Land"]=>
array(1) {
["Acreage"]=>
string(5) "false"
}
["Address"]=>
array(8) {
["StreetAddress"]=>
string(13) "301 main"
["AddressLine1"]=>
string(13) "301 main"
["StreetNumber"]=>
string(3) "301"
["StreetName"]=>
string(9) "main"
["City"]=>
string(7) "city"
["Province"]=>
string(7) "province"
["PostalCode"]=>
string(6) "H0H0H0"
["Country"]=>
string(6) "Canada"
}
["PropertyType"]=>
string(10) "Industrial"
["ZoningDescription"]=>
string(4) "COMM"
}
Is there a best practice for how to use Laravel & Eloquent/ORM to handle complex (but repeatable) data structures and datastreams like this?
I figure I can keep practicing with different migration/database structures and test how to best store and retrieve the data, but I thought it'd be helpful to hear about best practices first, or things others have tried first.
My hunch is that the easiest way is to store and retrieve the data is to resemble the data structure entirely and update it every time there's a structural change. The data is retrieved via a versioned API so this should be okay.
Let me know your thoughts. Thanks so much!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire