访问模型中的孩子

I have a relationship between two models. Instead of doing a @foreach to peruse through each child in the view, I want to access each child manually based on a condition, but not sure how to achieve this.

Parent model snippet

public function childs()
{
    return $this->hasMany('Child');
}

Child model snippet

public function parent()
{
    return $this->belongsTo('Parent');
}

view.blade.php

@foreach ($parents as $parent)
    @if ($parent->childs()->count() == 2)
        {{ $parent->find(1)->childs()->where('corner', '=', 'A')->first()->id }}
         and
        {{ $parent->find(1)->childs()->where('corner', '=', 'B')->first()->id }}
    @endif
@endforeach 

The reason I want to do this is because there will always be only 2 childs, I want to show them in a specific order, and I want to put the 'and' word in between.

With this what happens is its bringing the first result of the total childs in the table that meet the condition, not just the child that belong to the parent i have selected that meets the condition. There reason I put the first() is because I'm getting multiple results back, but in reality there will only be one child that meets the condition.

I'm pretty sure I'm over complicating it and there needs to be a simpler way.

Thanks for your help!!!


From Mudonat response, this is what I did.

Parent model snippet

public function childs()
{
    return $this->hasMany('Child');
}

Child model snippet

public function parent()
{
    return $this->belongsTo('Parent');
}

public function scopeCorner($query, $corner)
{
    return $query->whereCorner($corner)->first();
}

view.blade.php

@foreach ($parents as $parent)
    @if ($parent->childs()->count() == 2)
        {{ $parent->childs()->corner('A')->id }}
        and 
        {{ $parent->childs()->corner('B')->id }}
    @endif
@endforeach 

You can use scopes to make it a little simpler . http://laravel.com/docs/4.2/eloquent#query-scopes