gpt4 book ai didi

php - 关于使用 laravel 与多个模型/MySQL 表的问题

转载 作者:行者123 更新时间:2023-11-30 00:30:39 25 4
gpt4 key购买 nike

我是 Laravel + 框架的新手,遇到了一些问题。我阅读了 Laravel 文档并尝试在他们的论坛上寻求支持 - 没有结果/

在我当前的设置中 - 我遵循了 laravel 文档和代码

我有 1 个模型:用户

我在数据库中有 1 个表:users

登录/注册部分等一切正常......

但是现在我需要创建几个新表以及更多模型:

我在网上搜索过,没有教程或其他任何内容来指导我如何操作。

任何帮助将不胜感激。

尝试过:

在模型中 -

创建:profile.php

class Profile extends Eloquent implements UserInterface, RemindableInterface {

protected $table = 'profile';

}
  • 它似乎不起作用,我想知道我是否必须链接文件或 laravel 框架等中的某些内容。

P.s:我使用 artisan 和 migrations 来创建用户表

我现在直接在数据库中创建表,但我不知道如何访问它们,例如:

在用户表中,我可以使用:

Auth::user()->username - 获取用户名

但是在新表(配置文件)中 -

我完全不知道如何使用 Laravel 代码访问它。

最佳答案

您阅读过文档 http://laravel.com/docs/eloquent 吗? ?

在 ../app/models/内创建一个新文件

../app/models/Profile.php

** 注意文件与类名匹配

模型内部:

class Profile extends Eloquent {
protected $table = 'profile';
}

然后在您的 Controller 或路由闭包中通过以下方式访问模型

$profile = Profile::find(1);

$profile = App::make('Profile');
$profile->about = 'About the user';
$profile->save();

关于php - 关于使用 laravel 与多个模型/MySQL 表的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22549164/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com