Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store data model #20

Open
breizhwave opened this issue Feb 27, 2025 · 4 comments
Open

Store data model #20

breizhwave opened this issue Feb 27, 2025 · 4 comments

Comments

@breizhwave
Copy link

Hi, probably a beginner question but how do you link you rMatrix to a Model to store and retrieve data ? thks

@atmonshi
Copy link
Member

hey..

let say this your code:

Matrix::make('question')
    ->label('Tell us about your mod')

in your database you have a column question and in your model you cast it to array:

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

then the "selected" values will be stored as json on the column question :)

@breizhwave
Copy link
Author

thks, and whats your recommended method for setting column and row data with model data? thks

@breizhwave
Copy link
Author

OK I used this

->columnData( FixProduct::orderBy('title')->get()->pluck( 'title')->toArray())
->rowData(FixCAtegory::orderBy('title')->get()->pluck( 'title')->toArray())

and I get a nice json, how can I decode this ? isometimes I have true, true, true, sometimes Ids...

{"1":{"1":true},"2":[true],"3":{"3":true},"0":{"4":true},"4":[true,true,true,true,true]}

@atmonshi
Copy link
Member

atmonshi commented Mar 1, 2025

can you share the output of:

dd(
    FixProduct::orderBy('title')->get()->pluck( 'title')->toArray(),
    FixCAtegory::orderBy('title')->get()->pluck( 'title')->toArray()
);

so I can test.
the true is for the checked radio input. you also should pass an array with key => value as in the demo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants