I'm using laravel and i get this error:
Trying to get property of non-object (View: C:\laragon\www\al-Zad\resources\views\blog\index.blade.php)
the problem is in this line:
this are the models:
namespace App;
use Illuminate\Database\Eloquent\Model;
post model:
namespace App;
use Illuminate\Database\Eloquent\Model;
class post extends Model {
public function author()
{
return $this->belongsTo(User::class);
}
}
User model:
namespace App;
use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable { use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function posts()
{
return $this->hasMany(post::class);
}
}
Thanks for your help
via mohammed