我有一个问题,但我不知道如何搜索或制作它。 我有一个工作门户数据库。在 job_requirements 列中,当我添加新行时,我想保存一个列表并在显示它之后。
示例:
- 3 年工作经验。
- 等等
- 等等
我怎样才能使它像一个数组并用foreach循环显示它?谢谢。
最佳答案
您可以将数组作为 JSON 保存在数据库中。
来自 the docs :
The array cast type is particularly useful when working with columns that are stored as serialized JSON. For example, if your database has a JSON or TEXT field type that contains serialized JSON, adding the array cast to that attribute will automatically deserialize the attribute to a PHP array when you access it on your Eloquent model:
protected $casts = [
'job_requirments' => 'array',
];
Once the cast is defined, you may access the options attribute and it will automatically be deserialized from JSON into a PHP array. When you set the value of the options attribute, the given array will automatically be serialized back into JSON for storage
https://laravel.com/docs/5.5/eloquent-mutators#array-and-json-casting
关于php - 在数据库中保存一个列表,然后显示列表。拉维,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48049865/