未定义的变量uprofile laravel 5.4 [英] undefined variable uprofile laravel 5.4

查看:74
本文介绍了未定义的变量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

这篇关于未定义的变量uprofile laravel 5.4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆