-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes.php
70 lines (57 loc) · 1.77 KB
/
notes.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests\UploadRequest;
use App\Pack;
use App\User;
use Auth;
class PackController extends Controller
{
public function index() {
$packs = Pack::with('user')->get();
//return $this->transformPacks($packs);
//$packs = Pack::all();
$data = collect([
"packs" => $packs
]);
return view('welcome')->with([
"data" => $data,
"user" => Auth::user(),
"stimpack_client_url" => env("STIMPACK_CLIENT_URL")
]);
}
public function upload(UploadRequest $request) {
$pack = new Pack();
$pack->name = $request->name;
$pack->description = $request->description;
$pack->content = $request->content;
$pack->user_id = $this->user()->id;
$pack->icon = "cube";
$pack->save();
}
private function transformPacks($packs) {
return $packs->map(function($pack) {
return $this->transformPack($pack);
});
}
private function transformPack($pack) {
$pack->name = $pack->user->name . "/" . $pack->name;
// Eager loading crap
$userName = $pack->user->name;
unset($pack->user);
$pack->user = $userName;
unset($pack->user_id);
return $pack;
}
private function user()
{
return User::where('stimpack_io_token', request()->header('stimpack-io-token'))->first();
}
public function review($id) {
return Pack::find($id)->content;
}
public function resolve($author, $packName) {
$user = User::where('nickname', $author)->first();
return Pack::where('user_id', $user->id)->where('name', $packName)->first();
}
}