我是一个绝对的初学者,我试图在Laravel中做一个CRUD,但我无法弄清楚为什么我的变量没有被传递到视图,所以我可以有一个在表中动态显示它们。Laravel变量不通过
我的“路线”工作正常。
然后我控制器
public function getHome()
{
$results = Crud::index();
return view('pages/home', ['results' => $results]);
}
叫我 “界面污物” 模式
class Crud extends Model
{
public static function index()
{
return $results = DB::table('data')
->whereNotNull('id')
->get();
}
}
而作为控制器看到
@extends('main')
@section('title', '| Home')
@section('content')
<div class="container">
@include ('partials/_jumbotron')
<table class="table table-inverse">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
</tr>
</thead>
<tbody>
@if(!empty($results))
@foreach($results as $result)
<tr>
<td scope="row">$result->$id</th>
<td>$result->$first_name</td>
<td>$result->$last_name</td>
<td>$result->$username</td>
</tr>
@endforeach
@endif
</tbody>
</table>
</div>
@endsection
感谢您的帮助提前进入我的看法...我失去了我的想法 对不起,如果我不够具体..
Edit1:我照你说的做了,但我仍然没有向我的表格输出数据?在指定的代码中是否还有其他错误,或者是深层的错误?
EDIT2:谢谢大家对指出错误 - 刀片{{}}和对象属性 $对象 - > propertie不是$对象 - > $ propertie
当我固定的那些被明显否定输出错误我记得我有一个空数据库..侦探柯南 - 感谢大家的帮助
尝试使用'$ result-> first_name'并重复其他字段。注意箭头后没有$。这些不是变量,它们是对象的属性。 – ishegg