I'm new to Inertia and so far I was only able to share a single string as flash data via a session variable and middleware. That works, but How do I share an array ?
I tried with the same mechanism, then without middleware directly with Inertia::share() but nothing worked. Do I need to JSON it ? Thanks
Controller.php:
$recovery_codes= ['aaaaaaa43', 'bbbbbbb23', 'ccccccc80'];
Inertia::share('arrMsg', $recovery_codes);
Form.jsx | 1st try
const {arr} = usePage().props;
{arr.arrMsg && (
<div class="alert">{arr.arrMsg} </div>
)}
Form.jsx | 2nd try
const {arr} = usePage().props;
let msgList = [];
arr.arrMsg.forEach((key,index) => {
msgList.push(<li >{key} - {index}</li>);
});
{arr.arrMsg && (
<div><ul>
{msgList}
</ul></div>
)}
Error: Cannot read properties of undefined (reading 'arrMsg')
https://inertiajs.com/shared-data