php - 在数据库中保存一个列表,然后显示列表。拉维

标签 php mysql laravel

我有一个问题,但我不知道如何搜索或制作它。 我有一个工作门户数据库。在 job_requirements 列中,当我添加新行时,我想保存一个列表并在显示它之后。

示例:

  1. 3 年工作经验。
  2. 等等
  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/

相关文章:

php - 插入mysql的下拉列表中的值都是相同的

php - Wordpress:搜索结果分页仍然不起作用

php - 没有换行的 POST 失败,但换行有效?

mysql - 这个mysql查询可能吗?

javascript - jQuery 文件上传的用户系统

php - URL 中的日期 dd/mm/yyyy

php - 如何从 MySQL 中获取具有最新日期的行

php - 强制点击提交按钮两次

php - 订阅 private-asdf 所需的 Pusher 私有(private) channel 身份验证信息

javascript - Laravel:通过 min.js 文件 "Uncaught ReferenceError: HelloWeek is not defined"包含 javascript 代码