Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shahzadyounas's avatar

How to Show Mobile# of only Male Students in Laravel Blade Table

I use "gender" attribute in Users table. my users are male and female. i want to show mobile number of only "Male" students in laravel blade view. This is my Code of users.blade.php

      <table>
              <thead>
               <tr>
                <th>Name</th>
                <th>Email</th>
                <th>Mobile</th>
              </tr>
            </thead>
            <tbody>
             @foreach($users as $user)
              <td>{{$user->fname}}</td>
              <td>{{ $user->email }}</td>
              <td>{{ $user->mobile }}</td>// Here how to show only Male Students Mobile No. 
              @endforeach
            </tbody>
          </table>

0 likes
3 replies
tykus's avatar
tykus
Best Answer
Level 104

Any number of ways to approach this, e.g.

{{ $user->gender == "male" ? $user->mobile : '' }}
shahzadyounas's avatar
@foreach($users as $user) {{$i}} {{ $user->reg_number }} {{$user->fname." ". $user->lname}} {{ $user->email }} {{ $user->mobile }}
    <td>

Please or to participate in this conversation.