我在处理数据时已经看过几次这个错误,但是现在我只是想把数据发布到我的控制器而我不明白为什么我会看到这个错误,因为没有&# 39; t任何物体?
Trying to get property of non-object
视图 -
<form role="form" class="wizard" type="POST" action="{{ route('data.post') }}">
{{ csrf_field() }}
<input type="text" name="seo_score" value="" placeholder="SEO Score e.g. 82" class="col-md-3" maxlength="2"/>
<div class="col-md-4 col-md-offset-8 submit">
<hr>
<button type="submit" class="primary-btn">Submit</button>
</div>
</form>
路线 -
Route::get('/admin/overview/{id}', [
'uses' => '\App\Http\Controllers\AdminController@getSingle',
'as' => 'account.single',
'middleware' => ['auth', 'admin'],
]);
Route::post('/admin/overview/post', [
'uses' => '\App\Http\Controllers\AdminController@postData',
'as' => 'data.post',
'middleware' => ['auth', 'admin'],
]);
控制器 -
public function postData(Request $request) {
return redirect()->back();
}
答案 0 :(得分:1)
首先,html表单只有type="post"
而不是method="post
,所以首先出现了一些问题。这混淆了路线,我也试图回到我从另一个控制器传回数据的路线。我现在已经更新了路由并通过了get请求,因此不会失败。
Route::get('/admin/overview/{id}', [
'uses' => '\App\Http\Controllers\AdminController@getSingle',
'as' => 'account.single',
'middleware' => ['auth', 'admin'],
]);
Route::post('/admin/overview/{id}', [
'uses' => '\App\Http\Controllers\AdminController@postSingle',
'middleware' => ['auth', 'admin'],
]);