我正在使用 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/