Hello! Created relationships in laravel, and everything works until null values are met, help me figure it out, thanks in advance!
User model:
public function issues() { return $this->hasMany('App\Issues', 'worker'); } Model Issues:
public function user() { return $this->belongsTo('App\User', 'worker'); } Issues table:
Schema::table('issues', function (Blueprint $table) { $table->integer('worker')->nullable()->unsigned(); $table->foreign('worker')->references('id')->on('users')->onDelete('set null')->onUpdate('cascade'); }); Representation:
@foreach($issues as $issue) <tr> <td>{{ $issue->title }}</td> <td>{{ $issue->user->name }}</td> </tr> @endforeach As long as all foreign keys are specified, everything works, as null is encountered, then we get the error Trying to get the property of non-object , google, but something is not there.
{{ $issue->user ? $issue->user->name:'' }}{{ $issue->user ? $issue->user->name:'' }}- Orange_shadow