Skip to content

Commit a686752

Browse files
committed
Merge branch 'develop'
2 parents a72724c + bc5804b commit a686752

File tree

1 file changed

+60
-8
lines changed

1 file changed

+60
-8
lines changed

README.md

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,78 @@
33
> We create a parameter named 'filters' in our GET url.
44
> The Query Builder instance can accept it as where conditions so we don't have to write it in every modules.
55
6+
### Require
7+
8+
* Laravel 5.3 (lower version will add in future)
9+
610
### Install
11+
712
Run the following command from you terminal:
813

9-
composer require "guosheng1987/laravel-repository-query: 0.*"
14+
composer require "guosheng1987/laravel-repository-query:0.1.*"
1015

1116
or add this to require section in your composer.json file:
1217

13-
"laravel-repository-query/repositories": "0.*"
18+
"laravel-repository-query/repositories": "0.1.*"
1419

1520
last command
1621

1722
composer update
1823

1924
### Demo
20-
A simple demo could help us unserstand this library,Let's assume that you start to design your api which shows your user in diffent enterprises that contains several departments and positions.
25+
A simple demo could help us unserstand this library,Let's assume that we start to design our api which shows our users in diffent enterprises that contains several departments and positions.
2126
The relationship is Enterprises has some Departments,Department has some Positions,and Users belows to one of them,so we bulid four models '**User**','**Department**','**Position**','**Enterprise**' here
2227

23-
At first,in the route file, we find *web.php* and write a simple Resource Route here.(Laravel 5.2 or lower version also similiar)
28+
<?php
2429

25-
Route::resource('user', 'UserController');
30+
namespace App\Models;
31+
32+
use Illuminate\Notifications\Notifiable;
33+
use Illuminate\Foundation\Auth\User as Authenticatable;
34+
35+
use Hash;
36+
37+
class User extends Authenticatable
38+
{
39+
use Notifiable;
40+
41+
protected $guarded = ['id'];
2642

43+
/**
44+
* The attributes that are mass assignable.
45+
*
46+
* @var array
47+
*/
48+
//protected $fillable = [
49+
// 'username', 'password', 'realname', 'phone', 'visit', 'lasttime'
50+
//];
51+
52+
/**
53+
* The attributes that should be hidden for arrays.
54+
*
55+
* @var array
56+
*/
57+
protected $hidden = [
58+
'password', 'remember_token',
59+
];
60+
61+
/**
62+
* Using Hash to encrypt password when User model saved
63+
*
64+
* @param string $value raw password
65+
* @return void
66+
*/
67+
public function setPasswordAttribute($value)
68+
{
69+
$this->attributes['password'] = Hash::needsRehash($value) ? Hash::make($value) : $value;
70+
}
71+
}
72+
73+
To follow the laravel docs to fill other models in our code.Here I omitted them.
74+
75+
In the routes folder, we find *web.php* and write a simple Resource Route here.
76+
77+
Route::resource('user', 'UserController');
2778

2879
I consider Repository as an interactive Data Layer to help us insulate models and controllers ,so here we write a method named 'getUserPaginate' in UserController.
2980
And in Laravel Docs,they do it like this.
@@ -49,10 +100,11 @@ And in Laravel Docs,they do it like this.
49100

50101
public function index()
51102
{
52-
53103
$user = $this->users->getUserPaginate();
54-
55-
return view('user.index', ['user' => $user]);
104+
105+
$result = array('msg' => 'success', 'result' => $users->toArray());;
106+
107+
return response()->json($result);
56108
}
57109
}
58110

0 commit comments

Comments
 (0)