-1

ErrorException (E_ERROR) Trying to get property 'title' of non-object (View: D:\xampp\htdocs\xampp\practise\freecode\resources\views\profiles\edit.blade.php)

After migration, I face that problem.

edit.blade.file......

<input id="title"
  type="text"
  class="form-control @error('title') is-invalid @enderror" 
  name="title" 
  value="{{ old('title') ?? $user->profile->title }}" required 
  autocomplete="title" autofocus>

 @error('title')
    <span class="invalid-feedback" role="alert">
        <strong>{{ $message }}</strong>
    </span>
@enderror
Anant Kumar Singh
  • 68,309
  • 10
  • 50
  • 94

2 Answers2

0

You can beat it clean with double ??

<input id="title"
  type="text"
  class="form-control @error('title') is-invalid @enderror" 
  name="title" 
  value="{{ old('title') ?? ($user->profile->title ?? '') }}" required 
  autocomplete="title" autofocus>

I have checked ?? for $user->profile->title too.

Rahul
  • 17,770
  • 7
  • 39
  • 58
0

I do this and it's work.

user.php file.....

protected static function boot()
{
    parent:: boot(); 

        static::created(function($user){
            $user->profile()->create([
                'title'=>$user->username,
            ]);
        });
}