You must use a model as I said.
You are using DB... if you decide you want to continue to use DB instead of a model you have to do something like this...
private function formatPhoneNumber($phone) {
$ac = substr($phone, 0, 3);
$prefix = substr($phone, 3, 3);
$suffix = substr($phone, 6);
return "({$ac}) {$prefix}-{$suffix}";
}
public function index()
{
$admin_applist = DB::table('employmentapplication')
->select('id','Fname', 'Lname', 'phone', 'email')
->get();
foreach($admin_applist as $item){
$item->phone = $this->formatPhoneNumber($item->phone);
}
return view('/admin')->with(compact('admin_applist'));
}
But again, this is why laravel has models. This is a perfect example of where a model should be used. It needs to be used. You want to modify every single items phone number, and the model will do it for you.
Just read the examples you have been given, dont just take a function and be like... its cool it will work. There are explainations and people have spent time to go as far as explain it... each perosn has explained how to solve this, the three different people all have basically the exact same solution for you. USE A MODEL, and then USE A MUTATOR.