Undefined variable uprofile laravel 5.4

I use laravel framework 5.4 and write the following controller class:

class ProfileController extends Controller
{
 public function index(){
      $uprofile = DB::table('user_profile')->find(Auth::id()); 
   return view('folder.profile')->with('uprofile',$uprofile);
 }

route:

Route::get('/','ProfileController@index');

In the view, I use

@foreach($uprofile as $profile)             
    $profile->id
    @endforeach

What is wrong here?

+4
source share
2 answers

Change your method index()to:

public function index(){ 
    $uprofile = DB::table('user_profile')->where('userid','=',Auth::id())->first(); 
    return view('CityOfWorks.profile')->with('uprofile',$uprofile); 
}

also in view

@foreach($uprofile as $profile)             
    {{ $profile->id }}    // Blade views in curly braces
@endforeach
+1
source

in your index method, just remove $ uprofile

return view('folder.profile')->with('uprofile');
0
source

Source: https://habr.com/ru/post/1684514/


All Articles