Skip to content

Commit 29e1192

Browse files
committed
内容删除
1 parent c19e65c commit 29e1192

File tree

57 files changed

+1788
-53
lines changed

Some content is hidden

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

57 files changed

+1788
-53
lines changed

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

+64-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/Http/Controllers/ContentController.php

+12-7
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,13 @@ public function index ()
3333
return $query->where('tag_id', $tag_id);
3434
})->count();
3535

36-
$tag= Tag::where('id', request()->tag)->first();
37-
return view('content.index', compact( 'total','tag'));
36+
$tagModel=Tag::where('user_id', request()->user()->id)
37+
->when(request()->tag, function ($query, $tag_id) {
38+
return $query->where('id', $tag_id);
39+
})->first();
40+
41+
$tag= request()->tag??null;
42+
return view('content.index', compact('total','tag','tagModel'));
3843
}
3944

4045
/**
@@ -43,7 +48,7 @@ public function edit ()
4348
{
4449
$content = Note::find(request()->id);
4550
if (!$content) {
46-
return redirect()->route('content')->with('danger', '不存在的条目');
51+
return redirect()->route('content')->with('Error', '不存在的条目');
4752
}
4853

4954
if ($content->user_id != Auth::user()->id) {
@@ -64,7 +69,7 @@ public function update (ContentUpdateRequest $request)
6469
{
6570
$content = Note::find($request->id);
6671
if (!$content) {
67-
return redirect()->route('content.edit')->with('danger', '不存在的条目');
72+
return redirect()->route('content.edit')->with('Error', '不存在的条目');
6873
}
6974

7075
if ($content->user_id != $request->user()->id) {
@@ -74,7 +79,7 @@ public function update (ContentUpdateRequest $request)
7479
$content->text = $request->text;
7580
$content->tag_id = $request->tag_id;
7681
$content->save();
77-
return redirect()->route('content')->with('success', '修改成功');
82+
return redirect()->route('content')->with('Success', '修改成功');
7883
}
7984

8085

@@ -85,14 +90,14 @@ public function delete ()
8590
{
8691
$content = Note::find(request()->id);
8792
if (!$content) {
88-
return redirect()->route('content')->with('danger', '不存在的条目');
93+
return redirect()->route('content')->with('Error', '不存在的条目');
8994
}
9095

9196
if ($content->user_id != request()->user()->id) {
9297
abort(403);
9398
}
9499
$content->delete();
95-
return redirect()->route('content')->with('success', '删除成功');
100+
return redirect()->route('content')->with('Success', '删除成功');
96101

97102
}
98103

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Http\Requests\CreateNoteRequest;
6+
use App\Mail\MailDeliver;
7+
use App\Models\Note;
8+
use App\Models\Subscription;
9+
use App\Models\Tag;
10+
use Illuminate\Support\Carbon;
11+
use Illuminate\Support\Facades\Auth;
12+
13+
//todo 2. 用户维护自己的标签已经订阅取消功能
14+
15+
/**
16+
* Class HomeController
17+
* @package App\Http\Controllers
18+
*/
19+
class HomeController extends Controller
20+
{
21+
/**
22+
* Create a new controller instance.
23+
* @return void
24+
*/
25+
public function __construct ()
26+
{
27+
$this->middleware('auth');
28+
}
29+
30+
/**
31+
* Show the application dashboard.
32+
* @return \Illuminate\Contracts\Support\Renderable
33+
*/
34+
public function index ()
35+
{
36+
$user_id = Auth::user()->id;
37+
$count = Note::where('user_id', $user_id)->count();
38+
$tags = $this->tagMapping();
39+
return view('publish.show', compact('count', 'user_id', 'tags'));
40+
}
41+
42+
43+
/**
44+
* @param \App\Http\Requests\CreateNoteRequest $request
45+
* @return \Illuminate\Http\RedirectResponse
46+
*/
47+
public function create (CreateNoteRequest $request)
48+
{
49+
50+
$textArray = explode("<hr>", $request->text);
51+
foreach ($textArray as $value) {
52+
if (!$value) continue;
53+
if ($value) {
54+
$note = new Note();
55+
$note->user_id = $request->user_id;
56+
$note->tag_id = $request->tag_id;
57+
$note->title = $request->title;
58+
$note->text = $value;
59+
$note->save();
60+
}
61+
}
62+
session()->flash('success', '发布成功~');
63+
return redirect()->route('publish');
64+
}
65+
66+
67+
68+
69+
/**
70+
* @return mixed
71+
*/
72+
public function tagMapping ()
73+
{
74+
return Tag::where('user_id', request()->user()->id)->pluck('name', 'id');
75+
76+
}
77+
78+
/**
79+
* @param $user_id
80+
* @param array $tags
81+
* @return array
82+
*/
83+
public function getUserPushingContents (array $tags)
84+
{
85+
foreach ($tags as $tag_id) {
86+
$notes = Note::with(['author'])
87+
->orderByRaw("RAND()")
88+
->where('tag_id', $tag_id)
89+
->limit(1)
90+
->get();
91+
if ($notes->isNotEmpty()) {
92+
$response[] = $notes->pop();
93+
}
94+
95+
}
96+
97+
return $response ?? [];
98+
99+
100+
}
101+
102+
103+
104+
105+
/**
106+
* @return string
107+
*/
108+
public function preview ()
109+
{
110+
$mail = Note::with(['tag'])
111+
->where('id', request()->id)
112+
->where('user_id',request()->user()->id)
113+
->get();
114+
115+
if($mail->isEmpty()){
116+
abort(404);
117+
}
118+
119+
return (new MailDeliver($mail))->render();
120+
}
121+
122+
123+
}

0 commit comments

Comments
 (0)