0

i am making a schedule tasking in laravel, and i need to know the value for other table and, in this case i get the properties and later i save the periods in array from a foreign key in the tables properties, later i need value from "date" in the table periods, but when i get the log i get this.

[2017-07-21 18:11:50] local.INFO: [{"id":5,"title":"Hola","date":"2017-07-25"}] 
[2017-07-21 18:11:50] local.INFO: [{"id":4,"title":"dsfsd","date":"2017-07-26"}]
[2017-07-21 18:11:50] local.INFO: [{"id":4,"title":"dsfsd","date":"2017-07-26"}]
[2017-07-21 18:11:50] local.INFO: [{"id":4,"title":"dsfsd","date":"2017-07-26"}]

And i cant access to the index with $v->{"id"}, $v->id, $v["id"], i dont know if is for the way i save the information in dates, this is my function, thanks.

protected function schedule(Schedule $schedule)
{
    $schedule->call(function () {

        $properties = DB::table( 'properties' )->where( 'status', '=', 1 )->whereNotNull( 'id_client' )->whereNotNull( 'id_period' )->get();

        $dates = array();

        foreach ($properties as $k => $v) {
            $dates[$k] = DB::table( 'periods' )->where( 'id', '=', $v->id_period )->whereDate('date', '>', date('Y-m-d'))->get();
        }

        $properties_status = array();

        /* ----- HERE ---------*/
        foreach ($dates as $v) {
            Log::info($v);
        }


    })->everyMinute();
}

3 Answers 3

1

This is JSON. It's a kind of data format. You can decode it in PHP by using:

$var = json_decode($v, true);

And in $var you will get a normal array. Which you can simple check with print_r($var);.


Manual

PHP: json_decode

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, i know it jajajja
1

You should json_decode($v) so you can treat it like a struct. Otherwise it's just a string to you.

Comments

0

DB::table()->get() returns a collection, so this will work:

Log::info($v->id);

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.