【发布时间】:2021-06-06 21:28:04
【问题描述】:
我正在处理来自外部网站的 POST 请求,我可以存储数据,但如何在刀片上显示它。
控制器:
public function parse(Request $request)
{
$files = File::create([
'Data1' => $request->input('Data1'),
'Data2' => $request->input('Data2'),
'Data3' => $request->input('Data3'),
]);
return view('fileview');
}
路线:
Route::any('fileview', 'App\Http\Controllers\FilesController@Files')->name('parse');
刀片:
{{ $Data1 }}
编辑:
我从 returnURL 收到此错误,但数据存储完美
Trying to get property 'profile' of non-object (View: D:\Systems\final\resources\views\partials\dash-sidenav.blade.php) {"exception":"[object] (Facade\\Ignition\\Exceptions\\ViewException(code: 0): Trying to get property 'profile' of non-object (View: D:\\Systems\\final\ esources\\views\\partials\\dash-sidenav.blade.php) at D:\\Systems\\final\ esources\\views/partials/dash-sidenav.blade.php:4)
dash-sidenav.blade.php
@if ((Auth::User()->profile) && Auth::user()->profile->avatar_status == 1)
<img src="{{ Auth::user()->profile->avatar }}" alt="{{ Auth::user()->name }}" class="user-avatar-nav">
@else
<img src="{{asset('images/mascot.jpg')}}" alt="" class="user-avatar-nav" >
@endif
【问题讨论】:
-
尝试将
Auth::user()->profile->avatar_status == 1更改为Auth::user()->profile['avatar_status'] == 1,您的错误与显示POST请求无关。当您尝试将avatar_status作为对象访问时,此错误是profileis not an object。 -
试过了,仍然抛出同样的错误。
-
您能在控制器中添加
dd(Auth::user())并更新响应吗? -
我想我找到了问题,当我收到来自外部网站的 POST 请求时,会话丢失了。我尝试评论上面的错误,并显示另一个错误说
Trying to get property 'username' of non-object
标签: laravel post model-view-controller laravel-blade