【问题标题】:Save and Display POST request from external website in LARAVEL在 LARAVEL 中保存并显示来自外部网站的 POST 请求
【发布时间】: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()-&gt;profile-&gt;avatar_status == 1更改为Auth::user()-&gt;profile['avatar_status'] == 1,您的错误与显示POST请求无关。当您尝试将 avatar_status 作为对象访问时,此错误是 profile is not an object。
  • 试过了,仍然抛出同样的错误。
  • 您能在控制器中添加dd(Auth::user()) 并更新响应吗?
  • 我想我找到了问题,当我收到来自外部网站的 POST 请求时,会话丢失了。我尝试评论上面的错误,并显示另一个错误说Trying to get property 'username' of non-object

标签: laravel post model-view-controller laravel-blade


【解决方案1】:

编辑你的控制器并像这样添加-&gt;with()

public function parse(Request $request)
{
    $files = File::create([
        'Data1'      => $request->input('Data1'),
        'Data2'     => $request->input('Data2'),
        'Data3'       => $request->input('Data3'),
    ]);

    return view('fileview')->with('Data1', $request->input('Data1'));
}

【讨论】:

  • 我现在收到此错误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)
  • 我需要更多上下文,您发布的任何内容都没有引用“个人资料”属性。
猜你喜欢
  • 2013-12-07
  • 2020-05-11
  • 2012-12-03
  • 2023-03-03
  • 2010-12-29
  • 1970-01-01
  • 2013-02-26
  • 2015-03-20
  • 1970-01-01
相关资源
最近更新 更多