What's Wrong with this?

Posted 3 months ago by artisticre

I have a function that isn't working but cannot find it I get this error Undefined variable: profilelist

public function formatPhoneNumber($phone) {

 $ac = substr($phone, 1,3);
 $prefix = substr($phone,4,3);
 $suffix = substr($phone, 7);

 return "({$ac}) {$prefix}-{$suffix}";

public function index()
    $userID = Auth::user()->id;
   $profilelist = DB::table('users')
  ->select('id','name', 'phone', 'email')
  ->where('id' '=' $userID)

  foreach($profilelist as $profile){
      $profile->phone = $this->formatPhoneNumber($profile->phone);

   return view('/home')->with(compact($profilelist));

And on the blade I have

@foreach($profilelist as $u)
{{$u->name}} {{$u->phone}} - {{$u->email}}

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