Skip to content

Commit

Permalink
### v1.9.5
Browse files Browse the repository at this point in the history
  • Loading branch information
luffyzhao committed Aug 9, 2018
1 parent 0ff317f commit 1a8474a
Show file tree
Hide file tree
Showing 18 changed files with 364 additions and 112 deletions.
5 changes: 5 additions & 0 deletions doc/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CHANGELOG

### v1.9.5
- 增加join可嵌套使用
- repo增加方法newQuery
16 changes: 15 additions & 1 deletion examples/app/Http/Controllers/Api/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,22 @@ public function repoSearch(RepoSearch $search)
* @author luffyzhao@vip.126.com
*/
public function repoJoin(){
$join = [
[
'user' => 'left',
'one' => 'inner'
]
];

// $join = ['user.one'];
//
// $join = [
// [
// 'user', 'one'
// ]
// ];
return $this->respondWithSuccess(
$this->repo->join(['user'])->get(['*'])
$this->repo->with(['user'])->scope(['order'])->join($join)->get(['*'])
);
}

Expand Down
4 changes: 4 additions & 0 deletions examples/app/Model/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ class Order extends Model
public function user(){
return $this->belongsTo(User::class, 'user_id', 'id');
}

public function scopeOrder($query){
$query->orderBy('orders.id', 'desc');
}
}
10 changes: 10 additions & 0 deletions examples/app/Model/Role.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Role extends Model
{
//
}
14 changes: 14 additions & 0 deletions examples/app/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ class User extends Authenticatable implements RedisTokeSubject
public function order(){
return $this->hasMany(Order::class, 'user_id', 'id');
}

/**
* 一对
* @method role
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
* @author luffyzhao@vip.126.com
*/
public function role(){
return $this->belongsTo(Role::class, 'role_id', 'id');
}

public function one(){
return $this->hasOne(UserHasOne::class, 'user_id', 'id');
}
/**
* Get the identifier that will be stored in the subject claim of the JWT.
*
Expand Down
10 changes: 10 additions & 0 deletions examples/app/Model/UserHasOne.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class UserHasOne extends Model
{
protected $table = "user_has_one";
}
14 changes: 14 additions & 0 deletions examples/app/Repositories/Modules/Role/Eloquent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Repositories\Modules\Role;

use luffyzhao\laravelTools\Repositories\Facades\RepositoriesAbstract;
use Illuminate\Database\Eloquent\Model;

class Eloquent extends RepositoriesAbstract implements Interfaces
{
public function __construct(Model $model)
{
$this->model = $model;
}
}
10 changes: 10 additions & 0 deletions examples/app/Repositories/Modules/Role/Interfaces.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Repositories\Modules\Role;

use luffyzhao\laravelTools\Repositories\Facades\RepositoryInterface;

interface Interfaces extends RepositoryInterface
{
// code...
}
36 changes: 36 additions & 0 deletions examples/app/Repositories/Modules/Role/Provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Repositories\Modules\Role;

use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Application;
use Config;
use luffyzhao\laravelTools\Repositories\Cache\LaravelCache;
use App\Model\Role;

class Provider extends ServiceProvider
{
/**
* Bootstrap any application services.
*/
public function boot()
{
}

/**
* Register any application services.
*/
public function register()
{
$this->app->bind(Interfaces::class, function (Application $app) {
$repository = new Eloquent(new Role());
if (!Config::get('app.cache')) {
return $repository;
}

$cache = new LaravelCache($app['cache'], 'Role', 3600);

return new Cache($repository, $cache);
});
}
}
14 changes: 14 additions & 0 deletions examples/app/Repositories/Modules/UserHasOne/Eloquent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Repositories\Modules\UserHasOne;

use luffyzhao\laravelTools\Repositories\Facades\RepositoriesAbstract;
use Illuminate\Database\Eloquent\Model;

class Eloquent extends RepositoriesAbstract implements Interfaces
{
public function __construct(Model $model)
{
$this->model = $model;
}
}
10 changes: 10 additions & 0 deletions examples/app/Repositories/Modules/UserHasOne/Interfaces.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Repositories\Modules\UserHasOne;

use luffyzhao\laravelTools\Repositories\Facades\RepositoryInterface;

interface Interfaces extends RepositoryInterface
{
// code...
}
36 changes: 36 additions & 0 deletions examples/app/Repositories/Modules/UserHasOne/Provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Repositories\Modules\UserHasOne;

use Illuminate\Support\ServiceProvider;
use Illuminate\Foundation\Application;
use Config;
use luffyzhao\laravelTools\Repositories\Cache\LaravelCache;
use App\Model\UserHasOne;

class Provider extends ServiceProvider
{
/**
* Bootstrap any application services.
*/
public function boot()
{
}

/**
* Register any application services.
*/
public function register()
{
$this->app->bind(Interfaces::class, function (Application $app) {
$repository = new Eloquent(new UserHasOne());
if (!Config::get('app.cache')) {
return $repository;
}

$cache = new LaravelCache($app['cache'], 'UserHasOne', 3600);

return new Cache($repository, $cache);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('role_id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateRolesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('roles');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateUserHasOneTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('user_has_one', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('user_id');
$table->string('has');
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('user_has_one');
}
}
2 changes: 1 addition & 1 deletion examples/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

Route::middleware('guest:api')->post('token', 'TokenController@store');

Route::group(['middleware' => 'auth:api'], function($route){
Route::group([], function($route){
Route::delete('token', 'TokenController@destroy');
Route::get('token', 'TokenController@show');

Expand Down
16 changes: 16 additions & 0 deletions src/Repositories/Exceptions/RepoException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
/**
* luffy-laravel-tools
* RepoException.php.
* @author luffyzhao@vip.126.com
*/

namespace luffyzhao\laravelTools\Repositories\Exceptions;


use Exception;

class RepoException extends Exception
{

}
Loading

0 comments on commit 1a8474a

Please sign in to comment.