Home > Software design >  Trying to get property 'name' of non-object (View: C:\xampp\htdocs\joblister-laravel-8-
Trying to get property 'name' of non-object (View: C:\xampp\htdocs\joblister-laravel-8-

Time:07-29

I am working on a job portal and I am getting the following error when I want to display the job applicants to a company. I am not able to figure out where the error is, please help me!

Laravel is showing: This is the error screen shot

The code of my index.blade.php for this is:

@extends('layouts.account')

@section('content')
  <div >
    <div >
      Job Applications
    </div>
    <div >
      <div >
        <div >
          <p >Listing all the Applicants who applied for your <strong>job listings</strong>.</p>
          <div >
            <table >
              <thead>
                <tr>
                  <th>#</th>
                  <th>Applicant Name</th>
                  <th>Email</th>
                  <th>Job Title</th>
                  <th>Applied on</th>
                  <th>Actions</th>
                </tr>
              </thead>
              <tbody>
                @if($applications->count())
                  @foreach($applications as $application)
                  <tr>
                    <td>1</td>
                    <td>{{$application->user->name}}</td>
                    <td><a href="mailto:{{$application->user->email}}">{{$application->user->email}}</a></td>
                    <td><a href="{{route('post.show',['job'=>$application->post->id])}}">{{substr($application->post->job_title,0,14)}}...</a></td>
                    <td>{{$application->created_at}}</td>
                    <td><a href="{{route('jobApplication.show',['id'=>$application])}}" >View</a>
                      <form action="{{route('jobApplication.destroy')}}" method="POST" >
                        @csrf
                        @method('delete')
                        <input type="hidden" name="application_id" value="{{$application->id}}">
                        <button type="submit" >Delete</button>
                      </form>
                    </td>
                  </tr>
                  @endforeach
                @else
                  <tr>
                    <td>You haven't received any job applications.</td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                  </tr>
                @endif
              </tbody>
            </table>
          </div>
          <div >
            {{ $applications && $applications->links() }}
          </div>
        </div>
      </div>
    </div>
  </div>
@endSection

CodePudding user response:

If you are using the join relation with the Application and User table and the records are in $applications variable, Its clearly mentioned in error that the user doesn't exist. We can just tell from this piece of code what's wrong. Can you show us the controller thats passing the $applications value ? The possible solution could be $application->user['name'];

CodePudding user response:

Share your array formate for batter understanding and actual error

  • Related