我正在閱讀Laravel 5文檔,並在理解路由模型綁定時遇到了一些問題。Laravel 5文檔 - 路由模型綁定
我使用的示例代碼從here
所以,我添加一行RouteServiceProvider.php:
public function boot(Router $router)
{
parent::boot($router);
$router->model('user', 'App\User');
}
我添加的路由:用於
默認Laravel用戶模型。
<?php namespace App;
use Illuminate\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Passwords\CanResetPassword;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
class User extends Model implements AuthenticatableContract, CanResetPasswordContract {
use Authenticatable, CanResetPassword;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'email', 'password'];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = ['password', 'remember_token'];
}
而且我有MySQL表'users'。當我轉到URL http://blog.app/profile/1時,我希望看到ID爲1的用戶的數據,但我不明白如何獲取實際模型值。相反,我看到:
有沒有得到模型值任何特殊的方法?或者我錯過了什麼?
如果你'DD($用戶>名稱)' - 那是什麼節目? – Laurence 2015-02-11 05:53:38
實際上,@TheShiftExchange有一個好處,因爲模型看起來像是正確加載的。 – manix 2015-02-11 06:35:40
我得到了完全相同的問題。我向Laravel彙報。它在幾天前工作! – 2015-02-26 23:39:25