Laravel HTTP Test trying to get property "object" of undefined

Posted 6 months ago by mlazuardy

I'm Using HTTP Test with PHPUnit to create test with users feature

but when i run mySampleTest like this;

  $this->get(route('users.index'))->assertStatus(200);

while the method of index like this

  $users = User::paginate(15);
        return view('users.index',compact('users'));

and the view :

<tbody>
            @foreach ($users->where('id', '!=' ,auth()->id()) as $key => $user)
            <tr>
                <td>{{$key}}</td>
                <td>{{$user->name}}</td>
                <td>{{$user->role->name}}</td>
                <td>
                    <a href="{{route('users.show',$user->id)}}">Show</a>
                </td>
                <td>
                    <a href="{{route('users.edit',$user->id)}}">Edit</a>
                </td>
                <td>
                    <form action="{{route('users.destroy',$user->id)}}" method="post">
                        @csrf
                        @method("DELETE")
                        <button type="submit" class="btn btn-danger">Delete</button>
                    </form>
                </td>
            </tr>
            @endforeach
        </tbody>

it throw an error like "trying to get property 'name' of undefined, what's the problem with my test code?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.