Home:ALL Converter>how to access data in query after casting it to array in model

how to access data in query after casting it to array in model

Ask Time:2020-02-12T05:08:58         Author:moataz

Json Formatter

I am using laravel v5.2 when I tried to make my table columns data type Json that cause an error because of MySQL version. I read a solution about this I can make its type text and casting them in my model to the array like that

protected $casts = [
        'division1' => 'array',     
    ]; 

in my controller this my query

$devision= admin_panel::find(1);

when dd($devision->division1); the result is null but when I removed the casting it return the result with no proplem I tried this $devision= admin_panel::find(1)->toarray(); but also dd($devision['division1']); returns null

Author:moataz,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60177406/how-to-access-data-in-query-after-casting-it-to-array-in-model
yy