I am going to view My users table data (username,email) in index.blade.php file. I have UsersController.php like this
<?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);
}
}
My User Model is
<?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://ift.tt/ww139j" . md5(strtolower(trim($this->email))) . "?d=mm&s=40";
}
public function scopeUserr($query)
{
return $query->where('username',Auth::user()->id);
}
}
and index.blade.php is
@if(isset($user))
@foreach($user as $use)
<h1>{ !! $use->username !! }</h1>
@endforeach
@endif
@endsection
routes is
Route::get('/index', function(){
return view('users.index');
});
but when I visit index view is it display empty page (no error) and did not show name and email
how can fix this prob?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire