未定义的变量uprofile laravel 5.4

问题描述:

我正在使用laravel框架5.4并编写以下控制器类:

I am using laravel framework 5.4 and write 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::get('/','ProfileController@index');

我正在使用

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

这里似乎出了什么问题?

What seems wrong here?

将您的index()方法更改为:

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

也在view

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