1

I would like to separate the value that my $assets->property_id displaying... it output 122142 instead of [0] => 122, [1] = 142 and better should be in array format. I wanted to learn how to display this in array so that i can place this to another condition...

$user_id = $id;

$type = "TIC";
$asset = ClientPropertyManagement::where('client_id', '=', $user_id)->get();

foreach( $asset as $assets ) {

  if ( $assets->investment_type == $type ) {
    echo $property = $assets->property_id;      
  }

}

Im using Laravel 4.2 to display some multiple tables and some conditions to match certain values, etc...

Better Explanation:

I have 2 major tables that i need to connect, assets table and property table.

In my laravel controller, i need to determine first the user id of the current user once I get the value, I need to pass it under assets table to match multiple columns like: “client_id”, “investment_type”, and “property_id”.

Once the “client_id” match the “user id”, i need to check if there was “TIC” type under the “investment_type”, and if there’s a match case, i will need to get the “property_id” and pass it to the property table and get “property_mgmt_contact” value and create automated email alert notification.

3 Answers 3

1

Your $assets is in object format so to convert it to an array you need this

(array) $assets;

Your code will look like

foreach( $asset as $assets ) {
  $assetsarray =  (array) $assets;
  if ( $assetsarray['investment_type'] == $type ) {
    echo $property = $assetsarray['property_id'].'<br />';      
  }
}

If you want to see any array, you can do this

echo '<pre>';
var_dump($array);
echo '</pre>';
Sign up to request clarification or add additional context in comments.

2 Comments

it was Null when i echo the var_dump($array);
dont use echo there, just var_dump and replace "$array" with your array "$assets".
1

Use substr() to split up the string at the third character.

$id = $property = $assets->property_id; 
echo substr($id, 0, 3) . ' ' . substr($id, 3);

9 Comments

Use @Barak's response above, but he omitted the array part (and you didn't specify what kind of array you wanted: $data = array('first_part' => substr($id, 0, 3), 'second_part' => substr($id, 4));
I don't understand your comment. There's no comment from Barak.
Maybe your comment should be for the question, not my answer.
this is working, though i am not sure how to match this as $properties as variable inside another condition to match other certain table id...
I have no idea what you mean by that. You can assign the concatenated string to a variable, you can put them in an array, you can do anything you want with them. This is very basic programming.
|
0

So I figured out that the value from my $properties are already in array which is wrong in my first output and use echo instead of print_r. After initiate to another condition, I need to pass the properties values to another table named property and get contact by matching the property id.

$user_id = $id; // 6 (current logged user)
$asset = ClientPropertyManagement::where('assets.client_id', '=', $user_id)->get();

foreach( $asset as $assets ) {
  if( $assets->investment_type == "TIC"  ) {
    // get property_id under all TIC's column and
    // match the property_id to Property table to get the column of `property_mgmt_contact`.    
    $properties[] = $assets->property_id; 
    // print_r($properties);
  }
}

if( !empty($properties) ){
  $property = DB::table('property')->whereIn('id', $properties)->get();
  foreach( $property as $p ){
    //send email to this email
    $p->property_mgmt_contact;
  }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.