Skip to content

Commit e2a1024

Browse files
author
qiang.sun
committed
database & eloquent
1 parent d8994a7 commit e2a1024

File tree

66 files changed

+3217
-75
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+3217
-75
lines changed

app/Comment.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Illuminate\Database\Eloquent\SoftDeletes;
7+
8+
class Comment extends Model
9+
{
10+
use SoftDeletes;
11+
12+
// 要触发更新的父级关联关系
13+
protected $touches = [
14+
'commentable'
15+
];
16+
17+
protected $fillable = [
18+
'content', 'user_id'
19+
];
20+
21+
const PENDING = 0; # 待审核
22+
const NORMAL = 1; # 正常
23+
24+
public function commentable()
25+
{
26+
return $this->morphTo();
27+
}
28+
}

app/Country.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class Country extends Model
8+
{
9+
public function posts()
10+
{
11+
return $this->hasManyThrough(Post::class, User::class);
12+
}
13+
}

app/Events/UserDeleted.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use App\User;
6+
use Illuminate\Broadcasting\Channel;
7+
use Illuminate\Queue\SerializesModels;
8+
use Illuminate\Broadcasting\PrivateChannel;
9+
use Illuminate\Broadcasting\PresenceChannel;
10+
use Illuminate\Foundation\Events\Dispatchable;
11+
use Illuminate\Broadcasting\InteractsWithSockets;
12+
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
13+
14+
class UserDeleted
15+
{
16+
use Dispatchable, InteractsWithSockets, SerializesModels;
17+
18+
public $user;
19+
20+
/**
21+
* Create a new event instance.
22+
*
23+
* @return void
24+
*/
25+
public function __construct(User $user)
26+
{
27+
$this->user = $user;
28+
}
29+
30+
/**
31+
* Get the channels the event should broadcast on.
32+
*
33+
* @return \Illuminate\Broadcasting\Channel|array
34+
*/
35+
public function broadcastOn()
36+
{
37+
return new PrivateChannel('channel-name');
38+
}
39+
}

app/Events/UserDeleting.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
use App\User;
6+
use Illuminate\Broadcasting\Channel;
7+
use Illuminate\Queue\SerializesModels;
8+
use Illuminate\Broadcasting\PrivateChannel;
9+
use Illuminate\Broadcasting\PresenceChannel;
10+
use Illuminate\Foundation\Events\Dispatchable;
11+
use Illuminate\Broadcasting\InteractsWithSockets;
12+
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
13+
14+
class UserDeleting
15+
{
16+
use Dispatchable, InteractsWithSockets, SerializesModels;
17+
18+
public $user;
19+
20+
/**
21+
* Create a new event instance.
22+
*
23+
* @return void
24+
*/
25+
public function __construct(User $user)
26+
{
27+
$this->user = $user;
28+
}
29+
30+
/**
31+
* Get the channels the event should broadcast on.
32+
*
33+
* @return \Illuminate\Broadcasting\Channel|array
34+
*/
35+
public function broadcastOn()
36+
{
37+
return new PrivateChannel('channel-name');
38+
}
39+
}

app/Extensions/CustomRequest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: sunqiang
5+
* Date: 2018/11/28
6+
* Time: 10:40 PM
7+
*/
8+
9+
namespace App\Extensions;
10+
11+
use Illuminate\Http\Request;
12+
13+
class CustomRequest extends Request
14+
{
15+
16+
}

app/Extensions/MongoHandler.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: sunqiang
5+
* Date: 2018/11/28
6+
* Time: 6:11 PM
7+
*/
8+
9+
namespace App\Extensions;
10+
11+
class MongoHandler implements \SessionHandlerInterface
12+
{
13+
public function close()
14+
{
15+
// TODO: Implement close() method.
16+
}
17+
18+
public function destroy($session_id)
19+
{
20+
// TODO: Implement destroy() method.
21+
}
22+
23+
public function gc($maxlifetime)
24+
{
25+
// TODO: Implement gc() method.
26+
}
27+
28+
public function open($save_path, $name)
29+
{
30+
// TODO: Implement open() method.
31+
}
32+
33+
public function read($session_id)
34+
{
35+
// TODO: Implement read() method.
36+
}
37+
38+
public function write($session_id, $session_data)
39+
{
40+
// TODO: Implement write() method.
41+
}
42+
43+
}

app/Extensions/MongoStore.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: sunqiang
5+
* Date: 2018/11/28
6+
* Time: 5:42 PM
7+
*/
8+
9+
namespace App\Extensions;
10+
11+
12+
use Illuminate\Contracts\Cache\Store;
13+
14+
class MongoStore implements Store
15+
{
16+
public function get($key)
17+
{
18+
// TODO: Implement get() method.
19+
}
20+
21+
public function many(array $keys)
22+
{
23+
// TODO: Implement many() method.
24+
}
25+
26+
public function put($key, $value, $minutes)
27+
{
28+
// TODO: Implement put() method.
29+
}
30+
31+
public function putMany(array $values, $minutes)
32+
{
33+
// TODO: Implement putMany() method.
34+
}
35+
36+
public function increment($key, $value = 1)
37+
{
38+
// TODO: Implement increment() method.
39+
}
40+
41+
public function decrement($key, $value = 1)
42+
{
43+
// TODO: Implement decrement() method.
44+
}
45+
46+
public function forever($key, $value)
47+
{
48+
// TODO: Implement forever() method.
49+
}
50+
51+
public function forget($key)
52+
{
53+
// TODO: Implement forget() method.
54+
}
55+
56+
public function flush()
57+
{
58+
// TODO: Implement flush() method.
59+
}
60+
61+
public function getPrefix()
62+
{
63+
// TODO: Implement getPrefix() method.
64+
}
65+
66+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
class HomeController extends Controller
8+
{
9+
/**
10+
* Create a new controller instance.
11+
*
12+
* @return void
13+
*/
14+
public function __construct()
15+
{
16+
$this->middleware('auth');
17+
}
18+
19+
/**
20+
* Show the application dashboard.
21+
*
22+
* @return \Illuminate\Http\Response
23+
*/
24+
public function index()
25+
{
26+
return view('home');
27+
}
28+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Contracts\OrderRepositoryInterface;
6+
use Illuminate\Http\Request;
7+
use Illuminate\Support\Facades\Auth;
8+
9+
class OrderController extends Controller
10+
{
11+
private $orders;
12+
13+
public function __construct(OrderRepositoryInterface $orders)
14+
{
15+
$this->orders = $orders;
16+
}
17+
18+
public function getRecent()
19+
{
20+
$recent = $this->orders->getMostRecent(Auth::user());
21+
return view('orders.recent', compact('recent'));
22+
}
23+
}

0 commit comments

Comments
 (0)