I was wondering if there is a function or something else, where you can get an other element from a collection than the primary key... For example if votes would have a foreign key 'user_id', how do I check this? On the laravel doc there was only an example to check the primary key by using contains(). Can anyone help me out?
Example that checks if there is a vote with id = 2
@foreach($projects as $project)
@if ($project->votes->contains(2))
//
@endif
@endforeach
I would want something to check if there is a vote that has a 'user_id' = signed in users id
@foreach($projects as $project)
@if ($project->votes->contains('user_id' == Auth::id()))
//
@endif
@endforeach
if ($votes->contains('user_id', auth()->id())) {
//
}
In your model
public static checkForeign($thisId) {
( $thisId == Auth::user()->id ) ? return true : return false;
}
In the view
@if ( ModelName::checkForeign($project->votes->id) )
// Do something
@endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With