artisticre
4 months ago
109
19
Laravel

What's Wrong with this?

Posted 4 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)
  ->get()
  ->first();

  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}}
@endforeach

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