tusimo/laravel-reverse-relation 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

tusimo/laravel-reverse-relation

最新稳定版本:v1.0

Composer 安装命令:

composer require tusimo/laravel-reverse-relation

包简介

a one to one and one to many reverse relation for laravel

README 文档

README

Reverse relation for laravel eloquent. We define one to one and one to many relations. We often want to get the reverse relation which means we should query from database. And this is unnecessary.Because we maybe already get the data.

安装

  1. 修改composer.json
{
    "require":
    {
        "tusimo/laravel-reverse-relation": "^0.1"
    }
}
  1. 修改config/app.php
<?php
return [
    'providers' => [
        /*
         * Package Service Providers...
         */
        \Tusimo\ReverseRelation\ReverseRelationProvider::class,
    ]
];

使用

before:

class User extends Model {
    use \Tusimo\ReverseRelation\Traits\ReverseRelation;

    public function books ()
    {
        return $this->hasMany(Book::class);
    }
}

class Book extends Model {
    public function user ()
    {
        return $this->>belongsTo(User::class);
    }
}
$books = User::with('books')->first();
dd($books->first()->user);//we maybe use like this way.this will be a sql query for db.

after:

class User extends Model {
    use \Tusimo\ReverseRelation\Traits\ReverseRelation;

    public function books ()
    {
        return $this->hasMany(Book::class)->withReverse('user');
    }
}

class Book extends Model {
    public function user ()
    {
        return $this->>belongsTo(User::class);
    }
}
$books = User::with('books')->first();
dd($books->first()->user);//this time there will be no sql for db because we have already know.

support

also support for tusimo/embed-relation which is a new relation for laravel.

统计信息

  • 总下载量: 4.23k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-20