我有一个列表功能,允许用户向个性化列表中添加特定的文章。如果我将多篇文章添加到同一列表中。列表在下拉菜单中被复制。
示例:

我添加到特定列表中的文章越多。所以它会复制。
数据库表
list | id | person_id | name | description
| 1 15 | Test List | null
data_list_ref | id | list_id | data_uid
| 1 | 1 | 9b888e1e9e
| 2 | 1 | jZ-mAtgh查询
$lists = DB::table('list')
->leftJoin('data_ref_list', 'data_ref_list.list_id', '=', 'list.id')
->select('list.id', 'list.name', 'data_ref_list.data_uid')
->where('person_id', Auth::user()->person_id)
->get();刀片实现
$record->键是当前在浏览器中查看的“文章”。
@foreach($lists as $list)
@if($list->data_uid === $record->key)
// show the checked list
// user's cant add the same article twice to a specific list
@else
// show the user's other lists
@endif
@endforeach发布于 2016-09-29 12:20:20
试着使用雄辩的:人际关系。
创建两个模型https://laravel.com/docs/5.3/eloquent#defining-models,一个用于“列表”,一个用于data_list_ref。
在模型"list“中,创建与"data_list_ref”https://laravel.com/docs/5.3/eloquent-relationships#defining-relationships的关系
将模型包括在控制器中如下所示
use App\List;现在,如果您想从"List“和"data_list_ref”获取数据,您可以这样称呼它
$list = List::where('person_id', Auth::user()->person_id)->get();这是拉拉获取数据的方法。
https://stackoverflow.com/questions/39769008
复制相似问题