Q:

Call to undefined method App\Student::contains() in laravel

In my blade view, it is giving me an error Call to undefined method App\Student:: contains()
my controller
if($auth->user()->getRoleNames() == '["Parent"]'){
    $id = $auth->user()->Parents_id;
    $parent = ParentName::find($id);
    $student = $parent->students;
    $announce = AnnounceMent::get();
    $roletype='parent';
    return view('announcement.index',compact('student','roletype','announce')); 
 }

my view file 
@foreach($announce as $ann)
    @if($student->contains('id', $ann->student_id))
        <tr>
            <td>{{$i}}</td>
            <td>{{$ann->announcement_type}}</td>
            <td>
                <?php $course = \App\Course::find($ann->course_id) ?>
                {{$course->course_name}}
            </td>
            <td>
            <?php $student = \App\Student::find($ann->student_id) ?>
                    {{$student['firstname'].' '.$student['lastname']}}
            </td>
            <td>{{$ann->description}}</td>
            <td>
            <a class="btn btn-success" href='{{ url("viewannounce/{$ann->id}") }}'>View</a>
            </td>
        </tr>
    @endif
@php($i++)
@endforeach

this is my collection I am getting dd($students)
Collection {#595 ▼
#items: array:3 [▼
0 => Student {#596 }
1 => Student {#597 }
2 => Student {#598 }

]
}

A:

contains is a collection method, you are calling it with a non-collection, if it will be App\Student::all()->contains('something') it will work fine, but App\Student::find(1)->contains('something') or App\Student::contains('something') will not work
Tinker results
>>> App\User::find(1)->contains('email')
BadMethodCallException with message 'Call to undefined method App/User::contains()'
>>> App\User::all()->contains('email')
=> false
>>> App\User::contains('email')
BadMethodCallException with message 'Call to undefined method App/User::contains()'
>>>

You can do 
$student->id == $ann->student_id

in your situation, I guess.

