User Image Tutorial - can't get profile view...

aaron-wilson

Feb 26th, 2017 05:57 PM

I'm having a go at the User profile Image tutorial. I can't seem to get the the profile view to show. the error i'm receiving is:

ErrorException in 138d559faab81bd62411fb931f75f3e7a98ce5b8.php line 7: Trying to get property of non-object (View: /home/vagrant/sites/asl_rera/resources/views/profile.blade.php)

the 3 line error in the exception shows this:

at PhpEngine->evaluatePath('/home/vagrant/sites/asl_rera/storage/framework/views/138d559faab81bd62411fb931f75f3e7a98ce5b8.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'user' => null)) in CompilerEngine.php line 59

Basically saying that the name 'user' the was created in the profile fuction return view array is null....

what could be causing this?

mark

Feb 27th, 2017 10:18 AM

Can you please share the content of your resources/views/profile.blade.php file?

aaron-wilson

Feb 27th, 2017 05:24 PM

Here's my content of my resources/views/profile.blade.php:

@extends('user.layout.auth')

@section('content')

`<div class="container">
    <div class="row">
        <div id="main-spread">
            <div class="panel panel-default">
                <div class="panel-heading" id="panel-title">{{ Auth::user()->username }}'s RERA User Profile</div>
                <div class="panel-body" id="pb-zero">
                    <!-- Main Page Content Goes Here!!-->
                    <div class="form-container">
                        <div class="row">
                            <div class="panel with-nav-tabs panel-primary">
                                <div class="panel-heading" id="hdg-one">
                                    <ul class="nav nav-tabs" id="click-tabs">
                                        <li role="presentation" class="active" id="hcpro-li"><i class="fa fa-btn fa-address-card-o"></i><a role="tab" href="#dash-home-tab" aria-controls="user profile" data-toggle="tab">User Profile</a></li>
                                        <li role="presentation" id="admin-li"><i class="fa fa-btn fa-bank"></i><a role="tab" href="#wheelchairs-tab" aria-controls="wheelchairs" data-toggle="tab">User Account</a></li>
                                    </ul>
                                </div>
                                <div class="panel-body" id="pb-one">
                                    <div class="tab-content">
                                        <div role="tabpanel" class="tab-pane fade in active" id="dash-home-tab">
                                            <div class="form-container">
                                                <div class="row">
                                                    <div class="col-md-12">
                                                        <div class="panel panel-default" id="form-panel">
                                                            <div class="panel-heading" id="form-head">{{ Auth::user()->username }}'s Current Profile</div>
                                                            <div class="panel-body" id="pb_inside" >
                                                            </div>
                                                            <p class="help-desk" align="center">Having trouble with this App? Dial 484.596.HELP (4357)</p>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="tab-pane fade" id="wheelchairs-tab">
                                            <div class="form-container">
                                                <div class="row" id="form-row">
                                                    <div class="col-md-12">
                                                        <div class="panel panel-default">
                                                            <div class="panel-heading" id="wc-panel-head">
                                                                <h5 id="wc-req-head-title">{{ Auth::user()->username }}'s User Account</h5>
                                                            </div>
                                                            <div class="form-horizontal" role="form">
                                                                <!-- Start Of 2nd Tab User Account -->{{ csrf_field() }}
                                                                <img src="/uploads/avatars/{{ Auth::user()->avatar }}" style="width:150px; height:150px; float:left; border-radius:50%; margin-right:25px;">
                                                                <h2>{{ Auth::user()->firstname }} {{ Auth::user()->lastname }}'s Account</h2>
                                                            </div>
                                                                <p class="help-desk" id="app-help" align="center">Having trouble using this App? Dial 484.596.HELP (4357)</p>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>`

@endsection

mark

Feb 28th, 2017 08:05 AM

Around all of the usage of Auth::user()->something, please make sure to check that the user is authenticated, else Auth::user() will be null, and therefor you will get the error Trying to get property of non-object, since null os not a object.

aaron-wilson

Feb 28th, 2017 05:35 PM

I apologize I'm fairly new to laravel. How would I go about ensuring that the user is authenticated. I'm using laravel 5.3 and I did look over the authentical documentation. Would I use:

` use Illuminate\Support\Facades\Auth;

if (Auth::check()) { // The user is logged in... } ` Or could you point me to a better way of doing it?

mark

Feb 28th, 2017 07:32 PM

Yea

@if (Auth::check())
    ...
@endif
aaron-wilson

Mar 1st, 2017 03:36 PM

Would that be wrapped around the whole HTML tags after the @section and before the @endsection?

aaron-wilson

Mar 1st, 2017 07:25 PM

Now it keeps sending me back to the log in if I click on the profile link...

mark

Mar 2nd, 2017 07:53 AM

That seems like another issue, you might not be logged in, or your user does not keep being logged in.