index.blade.php 파일에서 내 사용자 테이블 데이터 (사용자 이름, 전자 메일)를 봅니다. 나는이Laravel 5.2에서 인덱스 메소드를 표시하는 방법
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
use App\User;
use App\Http\Requests;
class UserController extends Controller
{
public function index()
{
$users = User::userr()->get();
return view('users.index')->withUser($users);
}
}
내 사용자 모델처럼 UsersController.php을하는 것은
<?php
namespace App;
use Auth;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'username', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function getAvatarUrl()
{
return "http://www.gravatar.com/avatar/" . md5(strtolower(trim($this->email))) . "?d=mm&s=40";
}
public function scopeUserr($query)
{
return $query->where('username',Auth::user()->id);
}
}
하고 index.blade.php이다
@if(isset($user))
@foreach($user as $use)
<h1>{ !! $use->username !! }</h1>
@endforeach
@endif
@endsection
경로입니다
Route::get('/index', function(){
return view('users.index');
});
하지만 때 인덱스 뷰를 방문하면 빈 페이지가 표시됩니다. e (오류 없음). 이름 및 전자 메일이 표시되지 않았습니다.
어떻게이 문제를 해결할 수 있습니까?
사용자 모델에 userr() 메서드가 없습니다. 시도해보십시오 $ users = User :: scopeUserr() -> get(); 또한 변수 사용자를보기로 보내고 사용자를 순환하려고합니다. – Chris
내 사용자 모델에 userr() 메소드가 있습니다. 다시보기 ... – Fernando