phpmysqllaraveleloquentlaravel-datatables

Laravel mutator from JSON to php array to display in datatable


I'm trying to retrieve a list of aliases formatting as JSON within my database. However when I use the casts mutator it only removes the citation symbols.

Like the following: "[`SOME ALIAS HERE`]" Becomes: [`SOME ALIAS HERE`]

And nothing more than that.

As mentioned I've tried using the casts to turn it into a PHP array without luck. Any suggestions on how I potentially can resolve this issue I'm having?

    // SECTION Casts
    protected $casts = [
        'aliases' => 'array',
    ];

More info about the structure of the database itself can be found here: https://github.com/AsYetUntitled/Framework/blob/master/altislife.sql

Under the "Players" table.

EDIT: RUNNING LARAVEL 6

And to clarify what the data from the column would look like when using the cast mutator. It would look something like this

[[`license_civ_driver`,0],[`license_civ_boat`,0],[`license_civ_pilot`,0],[`license_civ_trucking`,0],[`license_civ_gun`,0],[`license_civ_dive`,0],[`license_civ_home`,0],[`license_civ_oil`,0],[`license_civ_diamond`,0],[`license_civ_salt`,0],[`license_civ_sand`,0],[`license_civ_iron`,0],[`license_civ_copper`,0],[`license_civ_cement`,0],[`license_civ_medmarijuana`,0],[`license_civ_cocaine`,0],[`license_civ_heroin`,0],[`license_civ_marijuana`,0],[`license_civ_rebel`,0]]


Solution

  • You are using backticks https://www.php.net/manual/en/language.operators.execution.php

    They are not single quotes.

    Furthermore if your data is formated as string. The cast will not work like that.