Q: trying to get property of non-object in school.php Hi I'm getting an Internal server error 500 when adding using laravel
in my School.php
    if(empty($Number[0])){ //  empty so start from 1
        $NextSchoolNumber = 1;
    }else{
        $NextSchoolNumber = ++$Number[0];
    }

    $NextSchoolCode = $City->code.$NextSchoolNumber; < this line here generates the error

    $School->schools_code = $NextSchoolCode;

Where $City comes from:
private $City; 

public function __construct(array $attributes = []) { 
    parent::__construct($attributes); 
    $this->City = new City; 
} 


A: Your data is an array and you are use as an objects, so you are getting this types of error.
Objects data format this types
$data->fields

But array format like below, Can try this,
$data['fields']


A: dd($City) and check whether code field exist or not.

A: well, thank you all,
I changed the code to 
$NextSchoolCode = $NextSchoolNumber;

and it worked fine. thanks again and sorry for the trouble. 
