我在正确理解 Laravel 模型时遇到一些困难。我们以框架提供的默认模型为例。
这是模型的全部内容:
User.php
<?php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password', 'remember_token');
}
我理解之间发生的一切{}
。但有些事情我完全迷失了:
比如,如何设置:
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
如果我要创建一个模型来假设表格,我是否需要它products
而不是桌子users
?我需要哪些use
如果该表不是用户表并且不需要身份验证?我也没有正确理解身份验证吗?
另外,还有另外一个:
class User extends Eloquent implements UserInterface, RemindableInterface
我知道我必须扩展雄辩的类才能与数据库交互,但关于实现的同样的问题:我需要将它们用于无用户表吗?我需要不同的吗?
感谢你们为我提供的所有帮助,如果我说得不够清楚,或者您有任何疑问,或者您想从我这里了解其他信息,请随时询问我。我真的很期待在进一步从事我现在正在工作的项目之前对 Laravel 中的模型有一个全面的理解,但由于缺乏关于我正在使用的技术的基本概念而不是由于编程工作中常见的技术困难。学习困难仅仅意味着你在学习时没有找到正确的方法。我被那只狗咬过好几次了。