【发布时间】:2017-04-12 00:26:22
【问题描述】:
我是 Laravel 新手,我收到以下错误 Undefined variable: no_student (Laravel 5.3) 这是我的看法。刀片
@foreach($no_marks as $no_mark)
<tr class="gradeX odd" role="row" id="">
<td style="display:none"></td>
<label class="mt-checkbox mt-checkbox-single mt-checkbox-outline">
<input type="checkbox" class="checkboxes checkbox-index" value="">
<span></span>
</label>
</td>
<td></td>
<td></td>
<td></td>
<td>
@endforeach
我在控制器中的索引方法
public function index()
{
//
$no_marks = Markno::orderBy('id', 'desc')->get();
return view('no-mark.index');
}
我正在使用这种存储方法存储记录
public function store(Request $request)
{
$this->validate($request, [
'ip_range' => 'required|max:255',
]);
$ip_data['ip_range'] = $request->input('ip_range');
$ip_data['min_ip'] = $request->input('ip_range');
$ip_data['max_ip'] = $request->input('ip_range');
$ip_data['list_id'] = $request->input('list_id');
$ip_data['user_id'] = Auth::user()->id;
$no_marks = Markno::create($ip_data);
session()->flash('msg', ' Successfully created');
return view('no-mark.index');
}
我不知道我哪里出错了。请帮忙解决。
【问题讨论】:
-
将您的索引方法更改为
return view('no-mark.index', compact('no_marks'));以将数据传递给视图。 -
非常感谢它的完成