多元关系拉拉维问题与观点



hi我想在我的应用程序中使用多态关系但它不能正常工作这是我的标签模型

namespace AppModels;
use AppModelsRootRoot;
class TagTab extends Root
{
public function taggable()
{
return $this->morphTo();
}
}

这是我的文章型号代码

<?php
namespace AppModels;
use AppModelsRootRoot;

class Article extends Root
{
public function articletags()
{
return $this->morphMany(TagTab::class, 'taggable');
}  
}

这是我的文章控制器代码

<?php
namespace AppHttpControllers;
use AppLibsMessage;
use AppModelsArticle;
use AppModelsTag;
use AppModelsTagTab;
use IlluminateHttpRequest;
use AppHttpControllersTagTabController;
/**
* Class ArticleController
* @package AppHttpControllers
*/
class ArticleController extends Controller
{
/**
* @var Article
*/
private $New;

/**
* ArticleController constructor.
*/
public function __construct()
{
$this->New = new Article();
}
/**
* @return IlluminateContractsViewFactory|IlluminateViewView
*/
public function index()
{
$articles = $this->New->index($this->Model);
return view('index', compact($articles));
}
}

这是我的索引页代码

<!-- index.blade.php -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Index Page</title>
<link rel="stylesheet" href="{{asset('css/app.css')}}">
</head>
<body>
<div class="container">
<br/>
@if (Session::has('success'))
<div class="alert alert-success">
<p>{{ Session::get('success') }}</p>
</div><br/>
@endif
<table class="table table-striped">
<thead>
<tr>
<th>ID</th>
<th>name</th>
<th>tags</th>
<th>created_at</th>
<th>updated_at</th>
<th colspan="2">Action</th>
</tr>
</thead>
<tbody>
@foreach($articles as $article)
@if($article->is_deleted==0)
<tr>
<td>{{$article->id}}</td>
<td>{{$article->title}}</td>
<td>{{$article->tags}}</td>
<td>{{jdate($article->created_at)->format('datetime')}}</td>
<td>{{jdate($article->updated_at)->format('datetime')}}</td>
<td><a href="{{action('ArticleController@edit', $article->id)}}"
class="btn btn-warning">Edit</a></td>
<td>
<form action="{{action('ArticleController@destroy', $article->id)}}" method="post">
@csrf
<input name="_method" type="hidden" value="DELETE">
<button class="btn btn-danger" type="submit">Delete</button>
</form>
</td>
</tr>
@endif
@endforeach
</tbody>
</table>
</div>
</body>
</html>

但当我加载索引页面时,我得到了这个

[{"id":4,"taggable_type":"App\Models\Article","taggable_id":2,"tag_id":1,"created_at":"2018-11-06 16:10:42","updated_at","2018-11.06 16:10:43"},{

在标签列而不是标签中,我看不到的问题在哪里

问题是我使用关系的方式我重新阅读了文档,对概念有了更好的理解并且知道如何正确使用

最新更新