我收到错误`试图获取非对象的属性{" userId":8," email"}

时间:2018-01-19 11:20:10

标签: php laravel

我是Laravel的新手。我一直在关注上述错误的许多问题和回答/答案,但我还没有完全了解它。

对于我的应用,当我使用注册用户登录并尝试查看我的个人资料时,我收到错误:

  

错误:试图获取非对象的属性{" userId":8," email" ...

请参阅下面我的ProfileController.php中的一些代码片段:

namespace App\Http\Controllers;

use App\Models\SmsVerificationToken;
use App\Notifications\SmsPhoneNumberVerification;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use Session;

class ProfileController extends Controller
{
/**
 * Create a new controller instance.
 *
 * @return void
 */
public function __construct()
{
    $this->middleware('auth');
    $this->middleware('read-news');
}

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
    $item = auth()->user();

    if(!$item->profile){
        return redirect()->to('/dashboard');
    }

    $current_transaction = $item->profile->current_transaction;

    if(!$current_transaction->is_complete){

        flash('You can not update your profile while you still have an incomplete transaction.')->error();

        return redirect()->to('/dashboard');
    }

    return view('profiles.index',compact('item'));
}

以及我的个人资料查看刀片:

@extends('layouts.app')

@section('content')

@component('dashboard.frame')
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3>
                Profile
            </h3>

            <p>{{ $item->email }}</p>

        </div>

        <div class="panel-body">

            <form class="form-horizontal" method="POST" action="/profile">
                {{ csrf_field() }}

                <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
                    <label for="name" class="col-md-4 control-label">Name</label>

                    <div class="col-md-6">
                        <input id="name" type="text" class="form-control" name="name" value="{{ old('name',$item->name) }}" required autofocus>

                        @if ($errors->has('name'))
                            <span class="help-block">
                                    <strong>{{ $errors->first('name') }}</strong>
                                </span>
                        @endif
                    </div>
                </div>

                <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
                    <label for="phone_number" class="col-md-4 control-label">Phone Number</label>

                    <div class="col-md-6">
                        <input id="phone_number" type="text" class="form-control" name="phone_number" value="{{ old('phone_number',$item->phone_number) }}" required>

                        @if ($errors->has('phone_number'))
                            <span class="help-block">
                                    <strong>{{ $errors->first('phone_number') }}</strong>
                                </span>
                        @endif
                    </div>
                </div>

0 个答案:

没有答案