noblemfd
1 month ago
157
2
Laravel

How to represent Attributes with Anonymous Alphabets in view blade

Posted 1 month ago by noblemfd

I have this code in Laravel:

public function index()
{
    $userCompany = Auth::user()->company_id;

        $departments = HrDepartment::where('company_id', $userCompany)->get();
    return view('hr.departments.index')->with('departments', $departments);
}

view

 @foreach($departments as $key => $department)
  <tr>
    <td>
       {{$key+1}}
    </td>
    <td>
       {{$department->dept_name ?? '' }}
    </td>
    <td>
       {{isset($department->dept_code) ? $department->dept_code : 'N/A'}}
    </td>
                                           
    </tr>
@endforeach 

I don't want the user to see the real department name ( {{$department->dept_name ?? '' }}), but to make it anonymous.

That is, it can randomize {{$department->dept_name ?? '' }} and represent each with alphabets. The first one can be A, second B, C, .... Z

How do I achieve this?

Thanks

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