在我的模型中,我具有功能
App\Akte.php
public function lvs() {
return $this->hasMany('App\lvs', 'lv_id');
}
在我的控制器中致电
public function index()
{
$aktes = \App\Akte::all();
return view('admin.akte.index', ['aktes' => $aktes]);
}
我想用lvs表扩展我的收藏$ aktes。有人可以解释如何做到这一点吗?
所以我的结果应该是一个集合,其中“ Akte”的每个元素都具有其lv的许多集合。.
答案 0 :(得分:0)
看到。可能对您的需求有用。
https://laravel.com/docs/5.7/eloquent-relationships
`rules: [
{
test: /\.tsx?$/,
use: [
{ loader: 'cache-loader' },
{
loader: 'thread-loader', // old plugin that cause performance problems: awesome-typescript-loader
options: {
workers: require('os').cpus().length - 1
}
},
{
loader: "ts-loader",
options: {
transpileOnly: true,
happyPackMode: true
}
},
{
loader: 'angular-router-loader'
},
{
loader: "angular2-template-loader"
}
]
},{
test: /\.js$/,
use: [
{
//loader: "babel-loader", options: {presets: ["es2015"]}
loader: 'happypack/loader'
}
],
exclude: '/node_modules/'
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader', //Exports HTML as string. HTML is minimized when the compiler demands.
}
]
}`
像这样的东西...
答案 1 :(得分:0)
如果您还希望加载关系,只需使用:
$aktes = \App\Akte::with('lvs')->get();