samedi 31 août 2019

facing Trying to get property 'name' of non-object problem can't solved it

When i am want to show my employee profile and want to add department and designation from another table i am facing this problem. I can't solved it..i saw previous question but can't solved my answers.

Controller:

public function show($id)
{
    $data['title'] = "Profile";
    $data['employee'] = Employee::with(['department','designation'])->findOrFail($id);
    $data['departments'] = Department::orderBy('name')->pluck('name','id');
    $data['designations'] = Designation::orderBy('name')->pluck('name','id');
    return view('admin.employee.show',$data);
}

view:

<li>
  <div class="title">Department:</div>
  <div class="text"></div>
</li>

Model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Notifications\Notifiable;

class Employee extends Model
{
    use SoftDeletes;
    use Notifiable;
    protected $fillable = [
        'firstname','lastname', 'email', 'password','designation_id','department_id'];

    public function designation()
    {
        return $this->belongsTo(Designation::class);
    }
    public function department()
    {
        return $this->belongsTo(Department::class);
    }
}

Trying to get property 'name' of non-object (View: C:\xampp\htdocs\hrm\resources\views\admin\employee\show.blade.php)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire