@laurentm you better show your controller and view code.
1/2 ErrorException in 44812f12bcefe0281da2f29a7f94d872 line 40: Trying to get property of non-object
I got this error when trying to access one view and I don't understand the error.
2/2 Whoops, looks like something went wrong. ErrorException in /path-to-app/storage/framework/views/44812f12bcefe0281da2f29a7f94d872 line 40: Trying to get property of non-object (View: /path-to-app/resources/views/backend/base/clients/companies/peoples/index_all.blade.php)
1/2 ErrorException in 44812f12bcefe0281da2f29a7f94d872 line 40: Trying to get property of non-object
@laurentm
show the area around line 40 of your index_all.blade.php, or whole file if possible.
@laracoft Line 40 may not be the actual line if he included some other files.
This is what is inside the view index_all.blade :
@extends('backend/base/layouts/default')
@section('title')
Clients Management
@stop
@section('header')
<link href="{{ asset('assets/plugins/forms/togglebutton/toggle-buttons.css') }}" type="text/css" rel="stylesheet" />
@stop
@section('content')
{{ Company::filterForm() }}</div>
<div class="col-lg-12">
<div class="page-header">
<h3>All People
<a href="{{ URL::route('clients.companies.peoples.create') }}" class="pull-right icon tip" title="Associate a People"><span class="icon16 iconic-icon-plus"></span></a>
</h3>
</div>
<div class="row">
<div class="col-lg-12">
<table cellpadding="0" cellspacing="0" border="0" class="dynamicTable display table dataTable">
<thead>
<tr>
<th>Full name</th>
<th>e-mail</th>
<th>Phone Number</th>
<th>Company</th>
<th>Country</th>
<th>City</th>
<th>Industry</th>
<th>Products</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
@foreach($companies as $company)
@foreach($company->peoples as $people)
<tr>
<td><a href="{{ URL::route('clients.companies.peoples.show', array($company->id, $people->id)) }}">{{ $people->fullName }}</a></td>
<td><a href="mailto:{{ $people->email1 }}">{{ $people->email1 }}</a></td>
<td><a href="skype:{{ $people->landline }}">{{ $people->landline }}</a></td>
<td><a href="{{ URL::route('clients.companies.show', $company->id) }}">{{ $company->name }}</a></td>
<td>{{ $company->country->name }}</td>
<td>{{ $company->city }}</td>
<td>
@foreach($company->industries as $industry)
{{ $industry->title }}
@endforeach
</td>
<td>{{ $company->tags }}</td>
<td>
<div class="left marginR10">
<div class="iToggle-button"><input type="checkbox" class="nostyle"
@if($people->User)
@if( !$people->User->isActivated() )
onchange="window.location.replace('/admin/users/{{encrypt($people->User->id)}}/activate');"
@else
checked="checked"
@if(!$people->User->isCurrent())
onchange="window.location.replace('/admin/users/{{encrypt($people->User->id)}}/deactivate');"
@else
disabled
@endif
@endif
@else
disabled
@endif
>
</div>
</div>
</td>
<td>
<a title="Update" class="tip" href="{{ URL::route('clients.companies.peoples.update', array($company->id, $people->id)) }}"><span class="icon16 typ-icon-pencil"></span></a>
@if(Sentry::getUser()->hasAccess('contacts'))
<a title="Delete" href="{{ URL::route('clients.companies.peoples.delete', array($company->id, $people->id)) }}"><span class="icon16 typ-icon-cross"></span></a>
@endif
</td>
</tr>
@endforeach
@endforeach
</tbody>
</table>
</div>
</div>
</div>
@stop
@section('footer_script')
<script type="text/javascript" src="{{ asset('assets/plugins/forms/togglebutton/jquery.toggle.buttons.js') }}"></script>
@stop
@section('footer')
<script type="text/javascript">
$('.iToggle-button').toggleButtons({
width: 70,
label: {
enabled: "<span class='icon16 icomoon-icon-checkmark white'></span>",
disabled: "<span class='icon16 icomoon-icon-close white marginL10'></span>"
}
});
function toggleButtons () {
$('.iToggle-button').toggleButtons({
width: 70,
label: {
enabled: "<span class='icon16 icomoon-icon-checkmark white'></span>",
disabled: "<span class='icon16 icomoon-icon-close white marginL10'></span>"
}
});
}
</script>
@stop
AND THIS IS LINE 40 : {{ $people->landline }}
and this is the beginning of controller :
namespace Controllers\Admin\Clients;
use BackendController;
use People;
use Redirect;
use Company;
use Config;
use Input;
use Activity;
use Todo;
use Sentry;
use Breadcrumbs;
use Email;
use EMailTemplate;
use Token;
use Lang;
use URL;
use Response;
use Validator;
use Session;
class PeoplesController extends BackendController {
public function __construct(){
parent::__construct();
if(Sentry::check() && !(Sentry::getUser()->hasAccess('contacts.peoples') || Sentry::getUser()->hasAccess('contacts'))){
throw new \PermissionDeniedException();
}
}
/**
* Display a listing of the resource.
*
* @return Response
*/
public function getIndex($id = null)
{
if($id == null)
{
$companies = Company::hasPermission(array('c', 'r', 'u', 'd'), Sentry::getUser()->id, false)->with('peoples', 'country', 'industries')->filter()->get();
Breadcrumbs::register('clients.peoples', function($b){
$b->parent('cp');
$b->push('Clients');
$b->push('Companies', route('clients.companies'));
$b->push('Peoples');
});
self::$breadcrumbs = Breadcrumbs::render('clients.peoples');
return self::view('clients/companies/peoples/index_all')
->with('companies', $companies);
}
else
{
$company = Company::hasPermission(array('c', 'r', 'u', 'd'), Sentry::getUser()->id, false)->with('peoples', 'country', 'industries')->filter()->find($id);
Breadcrumbs::register('clients.peoples', function($b, $company){
$b->parent('cp'); // @ we can actuall inherit this class from CompaniesController to make it easier and more structural.
$b->push('Clients');
$b->push('Companies', route('clients.companies'));
$b->push($company->name, route('clients.companies.show', $company->id));
$b->push('Peoples');
});
self::$breadcrumbs = Breadcrumbs::render('clients.peoples', $company);
return self::view('clients/companies/peoples/index')
->with('company', $company);
}
}
{{ $people->landline }} is probably not it.
Can you access /path-to-app/storage/framework/views/44812f12bcefe0281da2f29a7f94d872.php? I suspect you have some company with no peoples in it.
@laurentm if you are sure that you are getting issue for any particular access, then simply use optional().
For example-
{{ optional($people)->landline }}
Clients Management
<?php $__env->startSection('title'); ?>
Clients Management
<?php $__env->stopSection(); ?>
<?php $__env->startSection('header'); ?>
<link href="<?php echo asset('assets/plugins/forms/togglebutton/toggle-buttons.css'); ?>" type="text/css" rel="stylesheet" />
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
<?php echo Company::filterForm(); ?></div>
<div class="col-lg-12">
<div class="page-header">
<h3>All People
<a href="<?php echo URL::route('clients.companies.peoples.create'); ?>" class="pull-right icon tip" title="Associate a People"><span class="icon16 iconic-icon-plus"></span></a>
</h3>
</div>
<div class="row">
<div class="col-lg-12">
<table cellpadding="0" cellspacing="0" border="0" class="dynamicTable display table dataTable">
<thead>
<tr>
<th>Full name</th>
<th>e-mail</th>
<th>Phone Number</th>
<th>Company</th>
<th>Country</th>
<th>City</th>
<th>Industry</th>
<th>Products</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
<?php foreach($companies as $company): ?>
<?php foreach($company->peoples as $people): ?>
<tr>
<td><a href="<?php echo URL::route('clients.companies.peoples.show', array($company->id, $people->id)); ?>"><?php echo $people->fullName; ?></a></td>
<td><a href="mailto:<?php echo $people->email1; ?>"><?php echo $people->email1; ?></a></td>
<td><a href="skype:<?php echo $people->landline; ?>"><?php echo $people->landline; ?></a></td>
<td><a href="<?php echo URL::route('clients.companies.show', $company->id); ?>"><?php echo $company->name; ?></a></td>
<td><?php echo $company->country->name; ?></td>
<td><?php echo $company->city; ?></td>
<td>
<?php foreach($company->industries as $industry): ?>
<?php echo $industry->title; ?>
<?php endforeach; ?>
</td>
<td><?php echo $company->tags; ?></td>
<td>
<div class="left marginR10">
<div class="iToggle-button"><input type="checkbox" class="nostyle"
<?php if($people->User): ?>
<?php if( !$people->User->isActivated() ): ?>
onchange="window.location.replace('/admin/users/<?php echo encrypt($people->User->id); ?>/activate');"
<?php else: ?>
checked="checked"
<?php if(!$people->User->isCurrent()): ?>
onchange="window.location.replace('/admin/users/<?php echo encrypt($people->User->id); ?>/deactivate');"
<?php else: ?>
disabled
<?php endif; ?>
<?php endif; ?>
<?php else: ?>
disabled
<?php endif; ?>
>
</div>
</div>
</td>
<td>
<a title="Update" class="tip" href="<?php echo URL::route('clients.companies.peoples.update', array($company->id, $people->id)); ?>"><span class="icon16 typ-icon-pencil"></span></a>
<?php if(Sentry::getUser()->hasAccess('contacts')): ?>
<a title="Delete" href="<?php echo URL::route('clients.companies.peoples.delete', array($company->id, $people->id)); ?>"><span class="icon16 typ-icon-cross"></span></a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('footer_script'); ?>
<script type="text/javascript" src="<?php echo asset('assets/plugins/forms/togglebutton/jquery.toggle.buttons.js'); ?>"></script>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('footer'); ?>
<script type="text/javascript">
$('.iToggle-button').toggleButtons({
width: 70,
label: {
enabled: "<span class='icon16 icomoon-icon-checkmark white'></span>",
disabled: "<span class='icon16 icomoon-icon-close white marginL10'></span>"
}
});
function toggleButtons () {
$('.iToggle-button').toggleButtons({
width: 70,
label: {
enabled: "<span class='icon16 icomoon-icon-checkmark white'></span>",
disabled: "<span class='icon16 icomoon-icon-close white marginL10'></span>"
}
});
}
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('backend/base/layouts/default', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
ok, line 40 is <td><?php echo $company->country->name; ?></td>
You have a company that has no country.
Use <td>{{ optional($company->country)->name }}</td> to fix
i have replaced the code but now I still get this error:
FatalErrorException in Handler.php line 25:
Uncaught TypeError: Argument 1 passed to path\Exceptions\Handler::report() must be an instance of Exception, instance of Error given, called in /path/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 73 and defined in path/app/Exceptions/Handler.php:25
Stack trace:
#0 /path/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(73): path\Exceptions\Handler->report(Object(Error))
#1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Error))
#2 {main}
thrown
but i confirm the issue comes from the fact that variable $country is null. I have removed the line and it display the page properly (but I loose the country name value so I don't get the data I need.)
let me get this right:
- If you remove the
<td>{{ $company->country->name }}</td>, page loads with no error? - If you use
<td>{{ optional($company->country)->name }}</td>, you get new error? - Or you changed something else and got new error?
if i remove this line <td><?php echo ($company->country)->name; ?></td> from 2bb7451339b32b54531fced42e9ed396 file then the page display but obviously without the country name
if i replace the line with the optional one you mention in the 2bb7 file then the page display with written {{ optional($company->country)->name }} instead of country
If i remove this line <td><?php echo ($company->country)->name; ?></td> from index_all.blade.php then the page display but without the country value
if in the index_all.blade.php I replace the line with the optional you propose then I get the new error FatalErrorException in Handler.php line 25
If i replace the line by this one: <td>{{ $company->country_id }} then page display and fill with country id but not name obviously
in database we have a table countries with column: id / name so each country got an id and this is this id which is recorded in the table companies
I have exported the table companies in Excel and I didn't see any companies who don't get a value in countries. I have also checked in the table countries that each id got a name.
Do not modify 2bb7451339b32b54531fced42e9ed396, all changes must only be made to your blade file.
What happens when you change blade to <td>{{ optional($company->country)->name }}</td>?
I get this :
FatalErrorException in Handler.php line 25:
Uncaught TypeError: Argument 1 passed to L5\Exceptions\Handler::report() must be an instance of Exception, instance of Error given, called in /long_path/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 73 and defined in /long_path/app/Exceptions/Handler.php:25
Stack trace:
#0 /long_path/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php(73): L5\Exceptions\Handler->report(Object(Error))
#1 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleException(Object(Error))
#2 {main}
thrown
please note L5 in the first path. This app started its development in Laravel 4 and was later pushed to Laravel5 by one of our developper, may be there is a hit somewhere there (I am not sure)...
I see in the config/app.php those lines in the provider :
* Application Service Providers...
*/
'L5\Providers\AppServiceProvider',
'L5\Providers\BusServiceProvider',
'L5\Providers\ConfigServiceProvider',
'L5\Providers\EventServiceProvider',
'L5\Providers\RouteServiceProvider',
'L5\Providers\MacroServiceProvider',
I think initially before taking over the previous developper, the developper stored the application on a server within a subfolder L5. Now we have moved this application on another server which is not anymore in this subfolder L5.
L5 meaning? Laravel 5?
@laurentm Try
@if($company->country)
<td>{{ $company->country->name }}</td>
@endif
Yes it means Laravel 5
It display the page but not the country name. (column are shifted: company city go to company country column) I also find out that the controller People doesn't get " use Country" at the beginning of the file contrary to Company controller. I added it in People controler but not better.
when I try to {{dd($company) ?}} I get this : #relations: array:3 [▼ "peoples" => Collection {#5559 ▶} "country" => null "industries" => Collection {#5560 ▶}
Also, initially the developper placed the whole App folder in public_html folder of the server. After reading a few of your other posts yesterday I saw you mentionned to another op to use symbolic link and to update some files, which I did.
<td>
@if($company->country)
{{ $company->country->name }}
@endif
</td>
this time it doesn't shift the data but the country column is empty
Let's try and remember what has transpired.
You have a company that has no country.
Since there is no country, why do you expect the country column to be filled?
Because as i said above I have exported the whole table Companies in Excel and check that each company in this Excel table got a country_id associated.. I sucess to see those country_id in the dd ($company). The problem come from getting the associated country name from a pivot (table countries (id/name) I suppose.. The question is what makes that $company->country->name doesn't give the value name... ?
See your own post
when I try to {{dd($company) ?}} I get this : #relations: array:3 [▼ "peoples" => Collection {#5559 ▶} "country" => null "industries" => Collection {#5560 ▶}
"country" => null
table Companies got column country_id to associate a country to a company. It doesn't record the country name directly inside the Companies table.
In my understanding, we are calling wrongly what we want.
We want to call country_id, get the value of it , then query table Countries and get the name based on country_id value.
companies table (name, country_id)
countries table (id,name)
PS: my level in php and laravel is beginner/newby
You need to understand Laravel better.
When Laravel sees $company->country->name, it automatically knows to use country_id to query country table and get the name.
The issue now is you have some company that has an empty country_id.
As said, I have checked all one by one each entry in PHPMYADMIN and in Excel and all Companies got a country_id . I also checked that max country_id value is <= max id of countries.
Also imagine that if one record would miss one country_id then when I place your if statement code snipeet I should get a few empty cell in my table for the only record which miss the country_id, but here all my entry are empty and I don't believe my companies entry all miss country_id..
so logically thinking I suppose the problem is not that one company miss a country_id...
Do you know which file(s) handle/ensure this: "When Laravel sees $company->country->name, it automatically knows to use country_id to query country table and get the name." ?
/needmoreinfo
public function getIndex($id = null)
{
if($id == null)
{
$companies = Company::hasPermission(array('c', 'r', 'u', 'd'), Sentry::getUser()->id, false)->with('peoples', 'country', 'industries')->filter()->get();
dd(reset($companies)); // expand everything and show us the output
...
}
else
{
$company = Company::hasPermission(array('c', 'r', 'u', 'd'), Sentry::getUser()->id, false)->with('peoples', 'country', 'industries')->filter()->find($id);
dd($company); // expand everything and show us the output
...
}
}
Impossible to expand all. I got this:
array:814 [▶]
where the first 83 records looks like this:
0 => Company {#2287 ▼
+table: "companies"
+autoHydrateEntityFromInput: true
+forceEntityHydrationFromInput: true
#guarded: []
#fillable: array:36 [ …36]
#validator: null
+validationErrors: MessageBag {#2288 …2}
+throwOnValidation: false
+autoPurgeRedundantAttributes: false
#purgeFilters: array:1 [ …1]
#purgeFiltersInitialized: false
+autoHashPasswordAttributes: false
#connection: null
#primaryKey: "id"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:42 [ …42]
#original: array:42 [ …42]
#relations: array:3 [ …3]
#hidden: []
#visible: []
#appends: []
#dates: []
#casts: []
#touches: []
#observables: []
#with: []
#morphClass: null
+exists: true
form record 84 it turns like this and i can not expand it:
84 => Company {#2539 …30}
not sure if it can helps but when i look inside the table Companies in phpmyadmin, I see the highest id is 994....
@laurentm
Ok my bad, notice the 2 dd() are different. Which one is being dumped?
public function getIndex($id = null)
{
if($id == null)
{
$companies = Company::hasPermission(array('c', 'r', 'u', 'd'), Sentry::getUser()->id, false)->with('peoples', 'country', 'industries')->filter()->get();
dd(reset($companies)->toJson()); // expand everything and show us the output
...
}
else
{
$company = Company::hasPermission(array('c', 'r', 'u', 'd'), Sentry::getUser()->id, false)->with('peoples', 'country', 'industries')->filter()->find($id);
dd($company->toJson()); // expand everything and show us the output
...
}
}
Please or to participate in this conversation.