laravel - undefined variable uprofile laravel 5.4

标签 laravel laravel-5

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

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');

在 View 中我正在使用
@foreach($uprofile as $profile)             
    $profile->id
    @endforeach

这里似乎有什么问题?

最佳答案

更改您的 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

关于laravel - undefined variable uprofile laravel 5.4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45893651/

相关文章:

php - Laravel 5 - 如何检查用户名和密码是否与表匹配?

php - 如何安装 Laravel 5.2

php - 通过 BaseController 将信息从数据库发送到 SideNavigation Blade 好吗?

php - Laravel 5.3 多文件上传

php - 使用Count 比较两个关系

javascript - 按传单喜欢 Laravel 5.2 订购

Laravel 6.x - 缓存 'pagination()'

php - Elasticsearch 在处理日期时比 gte 更快

php - 更新 laravel 时,我得到 Only one of those can beinstalled : illuminate/view, laravel/framework。 laravel/framework 取代照亮/ View

mysql - 如何使用 Laravel 查询生成器从表并集的结果中选择列?