I'm trying to learn Laravel. I can see old docs and videos (from Laravel 5.4) speaking of Repositories and repository pattern, meaning classes to work with collections of data. But on the current (5.7) Laravel docs, I cannot find any reference to Repositories or the pattern itself. So I'm wandering: are still used (and thus I should study them) or maybe the 'new' ones are what it's called 'Collections'? Or maybe they are not at all related?
码龄 粉丝数 原力等级 --
- 被采纳
- 被点赞
- 采纳率

在今天的Laravel中,存储库是一个旧模式吗?
收起
- 写回答
- 好问题 0 提建议
- 关注问题
微信扫一扫
点击复制链接分享
- 邀请回答
- 编辑 收藏 删除 结题
- 收藏 举报
1条回答 默认 最新
- 关注
码龄 粉丝数 原力等级 --
- 被采纳
- 被点赞
- 采纳率
dongxian3852 2018-10-03 01:25关注Repositories are not implemented by default on Laravel. If you want to use them you need to implement yourself, or use a package. The repository pattern is a design pattern mainly use to abstract data access by returning standard classes for exemple, so this way if you decide to change your ORM from Eloquent to Doctrine, you will have to change only the repository, and the rest of your application will be fine. That help to build scalable and maintenable applications.
Now this is not mandatory at all, it's just good to know what it is and how to use it. But if your application is small, my advice would be : Don't bother with Repository. That's just gonna add more complexity to your code. But this is a really famous design pattern, so that's probably why it is in a lots of video and tutorials.
Collection : In Laravel, Collections are an object returned by the query builder when a query return more than one result. Collections have a lots of really handy methods to help you manipulate these data.
本回答被题主选为最佳回答 , 对您是否有帮助呢? 本回答被专家选为最佳回答 , 对您是否有帮助呢? 本回答被题主和专家选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏举报微信扫一扫
点击复制链接分享
编辑预览轻敲空格完成输入- 显示为
- 卡片
- 标题
- 链接
评论按下Enter换行,Ctrl+Enter发表内容

- 显示为
- 卡片
- 标题
- 链接
报告相同问题?
- 2018-11-23 01:53回答 1 已采纳 You can define 2 routes with the same name in both files and you won't get any errors. However, a
- 2017-09-20 11:16回答 1 已采纳 try this first in config/database.php add another connection 'connections' => [ 'mysql' =
- 2017-09-06 21:33回答 3 已采纳 Use Cars::brand because you declared functions as static public static function getBrand($data=nu
- 2021-05-07 12:16您可以实例化一个存储库一次,并以任何顺序对其进行任何操作,查询和模型操作方法都将继续起作用。 新增的功能之一是能够覆盖或“临时”设置和删除条件,以及在检索后对模型进行后处理。 我很清楚地知道,是非常...
- 2018-06-13 06:35回答 2 已采纳 You cannot. You can however just send the path string to your partial and use the @asset directive
- 2017-08-08 09:42回答 1 已采纳 All you would have to do is take the contents in the /public folder and put it in the desired subd
- 2019-04-11 02:58回答 3 已采纳 I hope this would help you $data = [ ['title' => '1st title', 'desc' => 'desc'], [
- 2021-06-01 12:35Laravel 的存储库模式 安装和配置 将此添加到您的 composer.json { " require " : { " reynholm/laravel-repositories " : " 0.16.* " } } 弃! 正如您在 packagist 上看到的那样,该软件包已被放弃。 我搬到...
- 2018-04-11 03:02回答 1 已采纳 You don't really need to inherit Models like class inherit. You should use Eloquent Relationship i
- 2019-02-28 02:52回答 3 已采纳 you don't even want to create StudentDetailsto get data using the code you have used. the model S
- 2018-07-26 01:00回答 2 已采纳 This is because Eloquent Collections which extend Support Collections use a dictionary that is key
- 2021-02-20 07:10Laravel存储库 关于 Laravel中构建存储库模式的框架。 要求 需要Laravel 6.0 用法 安装 $ composer require shintarosakata/laravel-repository 工匠命令 $ artisan make:repository $ artisan make:interface $ ...
- 2021-04-09 12:15Laravel中简化的存储库模式实现。 要求 Laravel 8.x 安装 执行以下命令以获取软件包的最新版本: composer require akunbeben/laravository 执行以下命令以创建RepositoryServiceProvider: php artisan ...
- 2021-05-03 05:59这是用于在laravel中实现存储库设计模式的示例代码。 加上基本的CRUD(创建,检索,更新和删除)操作。 如何安装? git clone https://github.com/manishgs/example-repository-design-pattern.git cd example-...
- 2021-06-26 16:31Laravel 仓库目标使用 laravel 框架为存储库实现提供通用接口。 为您提供一个很好的起点来创建简单且可维护的 Laravel 应用程序。 使用存储库模式和几行代码鼓励良好行为通过抽象复杂行为来简化您的代码清理您的模型...
- 没有解决我的问题, 去提问
- 京ICP备19004658号
- 经营性网站备案信息
公安备案号11010502030143
- 营业执照
- 北京互联网违法和不良信息举报中心
- 家长监护
- 中国互联网举报中心
- 网络110报警服务
- Chrome商店下载
- 账号管理规范
- 版权与免责声明
- 版权申诉
- 出版物许可证
- ©1999-2025北京创新乐知网络技术有限公司