Skip to content

Commit 55b5d37

Browse files
committed
admin panel added
1 parent fc9ab90 commit 55b5d37

File tree

141 files changed

+7986
-4794
lines changed

Some content is hidden

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

141 files changed

+7986
-4794
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Admin;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Http\Request;
7+
8+
class IndexController extends Controller
9+
{
10+
public function index()
11+
{
12+
return view('admin.index');
13+
}
14+
public function users()
15+
{
16+
if (!auth()->user()->can('access users'))
17+
{
18+
abort(403);
19+
}
20+
return view('admin.users.index');
21+
}
22+
public function tags()
23+
{
24+
if (!auth()->user()->can('access tags'))
25+
{
26+
abort(403);
27+
}
28+
return view('admin.tags.index');
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Admin;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Http\Request;
7+
use Spatie\Permission\Models\Permission;
8+
9+
class PermissionController extends Controller
10+
{
11+
public function index()
12+
{
13+
if (!auth()->user()->can('access permissions'))
14+
{
15+
abort(403);
16+
}
17+
return view('admin.permissions.index');
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Admin;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Http\Request;
7+
use Spatie\Permission\Models\Role;
8+
9+
class RoleController extends Controller
10+
{
11+
public function index()
12+
{
13+
if (!auth()->user()->can('access roles'))
14+
{
15+
abort(403);
16+
}
17+
18+
return view('admin.roles.index');
19+
}
20+
}

app/Http/Controllers/BlogController.php

+40-117
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
use App\Models\Comment;
99
use App\Models\Tag;
1010
use App\Models\User;
11+
use Illuminate\Support\Facades\URL;
1112
use Illuminate\Http\Request;
12-
use Illuminate\Support\Facades\Auth;
13-
13+
use Jorenvh\Share\ShareFacade;
1414
class BlogController extends Controller
1515
{
16+
public function __construct()
17+
{
18+
$this->middleware('auth')->except(['index', 'show']);
19+
}
1620
/**
1721
* Display a listing of the resource.
1822
*
@@ -30,82 +34,8 @@ public function index(Request $request)
3034
*/
3135
public function create()
3236
{
33-
if (Auth::check()) {
34-
$last_draft = Blog::where([['user_id', auth()->user()->id], ['status', "drafted"]])->OrderBy('updated_at', 'desc')->first();
35-
$tagTitles = [];
36-
if ($last_draft) {
37-
foreach ($last_draft->tags as $tag) {
38-
$tagTitles[] = $tag->title;
39-
}
40-
}
41-
$isDraftNull = 0;
42-
if ($last_draft) {
43-
$isDraftNull = 1;
44-
}
45-
return view("blogs.create")
46-
->with(["draft" => $last_draft, "tagTitles" => json_encode($tagTitles), "isDraftNull" => $isDraftNull]);
47-
} else {
48-
return view("auth.login")->with(["warning" => "You must be logged in to create Blog."]);
49-
}
50-
}
51-
52-
/**
53-
* Store a newly created resource in storage.
54-
*
55-
* @param \App\Http\Requests\StoreBlogRequest $request
56-
* @return \Illuminate\Http\Response
57-
*/
58-
public function draft(Request $request)
59-
{
60-
61-
$blogId = $request->get('blogId');
62-
$blogTitle = $request->get('blogTitle');
63-
$blogDescription = $request->get('blogDescription');
64-
$tagNames = json_decode($request->get('tags'));
65-
66-
if ($blogId != '') {
67-
68-
$blog = Blog::find($blogId);
69-
$blog->title = $blogTitle;
70-
$blog->description = $blogDescription;
71-
$tagIds = [];
72-
$tagTitles = [];
73-
foreach ($tagNames as $tagName) {
74-
$tag = Tag::firstOrCreate(['title' => $tagName]);
75-
if ($tag) {
76-
$tagIds[] = $tag->id;
77-
$tagTitles[] = $tag->title;
78-
}
79-
};
80-
$blog->save();
81-
$blog->tags()->sync($tagIds);
82-
} else {
83-
$blog = new Blog();
84-
$blog->title = $blogTitle;
85-
$blog->description = $blogDescription;
86-
$blog->status = "drafted";
87-
$blog->user_id = auth()->user()->id;
88-
$tagIds = [];
89-
$tagTitles = [];
90-
foreach ($tagNames as $tagName) {
91-
92-
$tag = Tag::firstOrCreate(['title' => $tagName]);
93-
if ($tag) {
94-
$tagIds[] = $tag->id;
95-
$tagTitles[] = $tag->title;
96-
}
97-
};
98-
$blog->save();
99-
$blog->tags()->sync($tagIds);
100-
101-
$blogId = $blog->id;
102-
}
103-
104-
return response()->json([
105-
"success" => 'post created successfully',
106-
"blogId" => $blogId,
107-
"tagTitles" => $request->get('tags')
108-
]);
37+
$this->authorize('create',Blog::class);
38+
return view("blogs.create");
10939
}
11040

11141
/**
@@ -117,50 +47,46 @@ public function draft(Request $request)
11747
public function show(Request $request, $slug)
11848
{
11949
$blog = Blog::where("slug", $slug)->first();
50+
$this->authorize('view', $blog);
12051
if ($blog) {
121-
if ($blog->status == "posted") {
122-
// $shareBlog = ShareFacade::page(
123-
// URL::current(),
124-
// $blog->title,
125-
// )
126-
// ->facebook()
127-
// ->twitter()
128-
// ->linkedin()
129-
// ->telegram()
130-
// ->whatsapp()
131-
// ->reddit()
132-
// ->getRawLinks();
133-
// dd($blog->body());
134-
135-
136-
$existView = BlogView::where([['ip_address', "=", $request->ip()], ["blog_id", "=", $blog->id]])->count();
137-
if ($existView < 1) {
138-
$newView = new BlogView();
139-
$newView->ip_address = $request->ip();
140-
$newView->blog_id = $blog->id;
141-
$newView->save();
142-
}
143-
$related = Blog::where("status", "=", "posted")->with(['user', 'tags', 'bloglikes', 'blogviews'])->whereHas('tags', function ($query) use ($blog) {
144-
$query->whereIn('title', $blog->tags->pluck('title'));
145-
}, '>=', count($blog->tags->pluck('title')))->where("id", "!=", $blog->id)->limit(5)->withCount('tags')
146-
->get();
147-
return view("blogs.show")->with([
148-
"blog" => $blog,
149-
"related" => $related,
150-
]);
52+
$shareBlog = ShareFacade::page(
53+
URL::current(),
54+
$blog->title,
55+
)
56+
->facebook()
57+
->twitter()
58+
->linkedin()
59+
->telegram()
60+
->whatsapp()
61+
->reddit()
62+
->getRawLinks();
63+
$existView = BlogView::where([['ip_address', "=", $request->ip()], ["blog_id", "=", $blog->id]])->count();
64+
if ($existView < 1) {
65+
$newView = new BlogView();
66+
$newView->ip_address = $request->ip();
67+
$newView->blog_id = $blog->id;
68+
$newView->save();
15169
}
70+
$related = Blog::published()->with(['user', 'tags', 'bloglikes', 'blogviews'])->whereHas('tags', function ($query) use ($blog) {
71+
$query->whereIn('title', $blog->tags->pluck('title'));
72+
}, '>=', count($blog->tags->pluck('title')))->where("id", "!=", $blog->id)->limit(5)->withCount('tags')
73+
->get();
74+
return view("blogs.show")->with([
75+
"blog" => $blog,
76+
"related" => $related,
77+
"shareBlog"=>$shareBlog,
78+
]);
15279
}
15380
return abort(404);;
15481
}
15582
public function edit($slug)
15683
{
15784
$blog = Blog::where("slug", $slug)->first();
158-
$this->Authorize('view', $blog);
85+
$this->authorize('update', $blog);
15986
if ($blog) {
16087
return view("blogs.update")->with(["blog" => $blog]);
16188
}
16289
}
163-
16490
public function manage($slug)
16591
{
16692
$blog = Blog::where("slug", $slug)->first();
@@ -232,13 +158,10 @@ public function tagSearch(Request $request, $slug)
232158
* @param \App\Models\Blog $blog
233159
* @return \Illuminate\Http\Response
234160
*/
235-
public function destroy(Request $request, $id)
161+
public function destroy(Blog $blog)
236162
{
237-
if (auth()->user()->id == $request->get('user_id')) {
238-
$blog = Blog::findOrFail($id);
239-
$blog->delete();
240-
return redirect('/blogs')->with(["deleteSuccess" => "blog deleted successfully."]);
241-
}
242-
return view('error');
163+
$this->authorize('delete', $blog);
164+
$blog->delete();
165+
return redirect('/blogs')->with(["deleteSuccess" => "blog deleted successfully."]);
243166
}
244167
}

app/Http/Controllers/PrivateProfileController.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ public function index(Request $request)
4545
]);
4646
} else if ($request->tab == "blogs") {
4747
$tab = 'blogs';
48-
$blogs = Blog::where("user_id", "=", auth()->user()->id)->where('status', '=', 'posted')->paginate(5);
48+
$blogs = Blog::where("user_id", "=", auth()->user()->id)->published()->paginate(5);
4949
return view("profile.private.index")->with([
5050
"user" => $user,
5151
"blogs" => $blogs,
5252
"tab" => $tab
5353
]);
5454
} else if ($request->tab == "drafts") {
5555
$tab = 'drafts';
56-
$drafts = Blog::where("user_id", "=", auth()->user()->id)->where('status', '=', 'drafted')->paginate(5);
56+
$drafts = Blog::where("user_id", "=", auth()->user()->id)->unpublished()->paginate(5);
5757
return view("profile.private.index")->with([
5858
"user" => $user,
5959
"drafts" => $drafts,
@@ -90,7 +90,7 @@ public function index(Request $request)
9090
]);
9191
} else if ($request->tab == 'comments') {
9292
$tab = 'comments';
93-
$comments = Comment::where('user_id', '=', Auth()->user()->id)->get();
93+
$comments = Comment::where('user_id', '=', Auth()->user()->id)->orderBy('created_at','DESC')->paginate(20);
9494
// ->paginate(5);
9595
return view("profile.private.index")->with([
9696
"user" => $user,

app/Http/Controllers/PublicProfileController.php

+1-22
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function index(Request $request, $username)
2727
if ($request->tab == 'blogs') {
2828
$tab = 'blogs';
2929
$pins = BlogPin::where("user_id", "=", $id)->get();
30-
$blogs = Blog::with('user','tags')->where("user_id", "=", $id)->where([['status', '=', 'posted'], ["is_pinned", "=", false]])->paginate(5);
30+
$blogs = Blog::with('user','tags')->where([["user_id", "=", $id],["is_pinned", "=", false]])->published()->paginate(5);
3131
return view("profile.public.index")->with([
3232
"user" => $user,
3333
"pins" => $pins,
@@ -62,27 +62,6 @@ public function index(Request $request, $username)
6262
}
6363
}
6464
}
65-
// public function detailCard(Request $request)
66-
// {
67-
// $userId = $request->get('userId');
68-
69-
// $user = User::query()->where('id', '=', $userId)
70-
// ->withCount('friendships')->first();
71-
// $friendship = NULL;
72-
// if (Auth::check()) {
73-
// $friendship = Friendship::where([
74-
// ["user_id", "=", $userId],
75-
// ["follower_id", "=", auth()->user()->id]
76-
// ])->count();
77-
// }
78-
79-
// $html = view("profile.public.popover")
80-
// ->with([
81-
// "user" => $user,
82-
// "friendship" => $friendship,
83-
// ])->render();
84-
// return response()->json($html);
85-
// }
8665
/**
8766
* Show the form for creating a new resource.
8867
*

0 commit comments

Comments
 (0)