code cleanup

This commit is contained in:
Conkley 2022-07-26 11:33:19 +10:00
parent ebacd4b44d
commit f4a5e735d1
11 changed files with 99 additions and 105 deletions

View File

@ -17,9 +17,9 @@ class AdminController extends Controller
public function users(Request $request)
{
if ($request->searchBy == 'name' && $request->has('q')) {
$users = DB::table('users')->where('name', 'LIKE', '%' . $request->q . '%')->paginate(10);
$users = User::where('name', 'LIKE', '%' . $request->q . '%')->paginate(10);
} else if ($request->searchBy == 'id' && $request->has('q')) {
$users = DB::table('users')->where('id', $request->q)->paginate(10);
$users = User::where('id', $request->q)->paginate(10);
} else {
$users = User::paginate(10);
}
@ -51,6 +51,6 @@ class AdminController extends Controller
'invited_by' => $invited_by,
];
return view('admin.tree')->with('data', $data);
return view('admin.tree')->with($data);
}
}

View File

@ -55,7 +55,7 @@ class FriendController extends Controller
public function accept($id): void
{
$user = Auth::user();
$recipient = User::find($id);
$recipient = User::findOrFail($id);
if (!$user->hasFriendRequestFrom($recipient)) {
abort(404);
@ -67,7 +67,7 @@ class FriendController extends Controller
public function decline($id): void
{
$user = Auth::user();
$recipient = User::find($id);
$recipient = User::findOrFail($id);
if (!$user->hasFriendRequestFrom($recipient)) {
abort(404);
@ -79,9 +79,9 @@ class FriendController extends Controller
public function add($id)
{
$user = Auth::user();
$recipient = User::find($id);
$recipient = User::findOrFail($id);
if (!$recipient || $recipient->id == $user->id) {
if ($recipient->id == $user->id) {
abort(404);
}
@ -96,9 +96,9 @@ class FriendController extends Controller
public function remove($id)
{
$user = Auth::user();
$recipient = User::find($id);
$recipient = User::findOrFail($id);
if (!$recipient || $recipient->id == $user->id) {
if ($recipient->id == $user->id) {
abort(404);
}

View File

@ -25,7 +25,7 @@ class HomeController extends Controller
*/
public function index()
{
if (auth()->user()) {
if (Auth::check()) {
return redirect(route('home'));
}
return view('index');
@ -43,21 +43,21 @@ class HomeController extends Controller
}
$query->whereIn('user_id', $friendIds)
->orWhere('user_id', '=', Auth::id());
})->orderBy('id', 'desc')->paginate(10, ["*"], "feedPage");
->orWhere('user_id', Auth::id());
})->latest()->paginate(10, ["*"], "feedPage");
$data = [
'friends' => $friends,
'posts' => $posts,
];
return view('home')->with('data', $data);
return view('home')->with($data);
}
public function feed_post(Request $request)
{
$request->validate([
'status' => 'required|min:3|max:100'
'status' => ['required', 'min:3', 'max:100']
]);
$post = new FeedPost;

View File

@ -13,8 +13,8 @@ class KeyController extends Controller
{
public function index()
{
$fetchKeys = InviteKey::where('created_by', Auth::id())->orderBy('id', 'desc')->get();
$activeKey = InviteKey::where('created_by', Auth::id())->orderBy('id', 'desc')->first();
$fetchKeys = InviteKey::where('created_by', Auth::id())->latest()->get();
$activeKey = InviteKey::where('created_by', Auth::id())->latest()->first();
if (!$fetchKeys->isEmpty()) {
if ($activeKey->created_at->addWeek()->gt(Carbon::now())) {
@ -36,8 +36,8 @@ class KeyController extends Controller
public function create()
{
$fetchKeys = InviteKey::where('created_by', Auth::id())->orderBy('id', 'desc')->get();
$activeKey = InviteKey::where('created_by', Auth::id())->orderBy('id', 'desc')->first();
$fetchKeys = InviteKey::where('created_by', Auth::id())->latest()->get();
$activeKey = InviteKey::where('created_by', Auth::id())->latest()->first();
// Validation
if (!$fetchKeys->isEmpty() && $activeKey->created_at->addWeek()->gt(Carbon::now())) {

View File

@ -12,21 +12,21 @@ class MessageController extends Controller
{
public function inbox()
{
$messages = Message::where('sendto_id', Auth::id())->where('deleted', false)->orderBy('id', 'desc')->paginate(10);
$messages = Message::where('sendto_id', Auth::id())->where('deleted', false)->latest()->paginate(10);
return view('messages.index')->with('messages', $messages);
}
public function inbox_sent()
{
$messages = Message::where('user_id', Auth::id())->orderBy('id', 'desc')->paginate(10);
$messages = Message::where('user_id', Auth::id())->latest()->paginate(10);
return view('messages.sent')->with('messages', $messages);
}
public function deleted()
{
$messages = Message::where('sendto_id', Auth::id())->where('deleted', true)->orderBy('id', 'desc')->paginate(10);
$messages = Message::where('sendto_id', Auth::id())->where('deleted', true)->latest()->paginate(10);
return view('messages.deleted')->with('messages', $messages);
}

View File

@ -27,13 +27,8 @@ class PageController extends Controller
public function profile($id)
{
$user = User::find($id);
$user = User::findOrFail($id);
$badges = DB::table('badges')->get();
if (!$user) {
abort(404);
}
$friends = $user->getFriends($perPage = 3);
$data = [
@ -42,16 +37,12 @@ class PageController extends Controller
'friends' => $friends
];
return view('pages.profile')->with('data', $data);
return view('pages.profile')->with($data);
}
public function profile_friends($id)
{
$user = User::find($id);
if (!$user) {
abort(404);
}
$user = User::findOrFail($id);
$friends = $user->getFriends($perPage = 10);
$data = [
@ -59,13 +50,13 @@ class PageController extends Controller
'friends' => $friends
];
return view('pages.profile_friends')->with('data', $data);
return view('pages.profile_friends')->with($data);
}
public function mutual_friends($id)
{
$user = User::find($id);
if (!$user || $user->id == Auth::id()) {
$user = User::findOrFail($id);
if ($user->id == Auth::id()) {
abort(404);
}
@ -76,13 +67,13 @@ class PageController extends Controller
'friends' => $friends
];
return view('pages.mutual_friends')->with('data', $data);
return view('pages.mutual_friends')->with($data);
}
public function users(Request $request)
{
if ($request->has('q')) {
$users = DB::table('users')->where('name', 'LIKE', '%' . $request->q . '%')->paginate(10);
$users = User::where('name', 'LIKE', '%' . $request->q . '%')->paginate(10);
} else {
$users = User::paginate(10);
}

View File

@ -26,19 +26,19 @@
name="searchBy" value="name">Search by Username</button><button class="bluebutton"
style="margin-left:2px" name="searchBy" value="id">Search by ID</button></div>
</form>
@if ($data['user'])
@if ($user)
<div id="SearchContainer">
<h2>User Found: {{ $data['user']->name }}</h2>
<h2>User Found: {{ $user->name }}</h2>
<ul>
<li>
<h3><a
href="{{ route('profile', App\Models\User::where('name', $data['invited_by'])->first()->id) }}" target="_blank">{{ $data['invited_by'] }}</a>
href="{{ route('profile', App\Models\User::where('name', $invited_by)->first()->id) }}" target="_blank">{{ $invited_by }}</a>
</h3>
</li>
<ul>
<li><a href="{{ route('profile', $data['user']->id) }}" target="_blank">{{ $data['user']->name }}</a></li>
<li><a href="{{ route('profile', $user->id) }}" target="_blank">{{ $user->name }}</a></li>
<ul>
@foreach ($data['children'] as $child)
@foreach ($children as $child)
<li><a href="{{ route('profile', $child->id) }}" target="_blank">{{ $child->name }}</a></li>
@endforeach
</ul>
@ -48,7 +48,7 @@
@endif
@if (!request()->has('q'))
<h5>Enter a username or ID.</h5>
@elseif (!$data['user'])
@elseif (!$user)
<h5>No user was found, check if you entered the correct details.</h5>
@endif
</div>

View File

@ -22,7 +22,8 @@
<input id="FeedBox" type="text" name="status" placeholder="Say something..." style="width: 80%;"
value="{{ old('status') }}">
<button style="width: 20%;height: 28px;margin-left: 10px;" class="greybutton" id="FeedButton"
type="submit" alt="Post it!, Button" onClick="this.form.submit();this.disabled=true;this.innerText='Posting…';">Post
type="submit" alt="Post it!, Button"
onClick="this.form.submit();this.disabled=true;this.innerText='Posting…';">Post
it!</button>
</p>
@if ($errors->any())
@ -34,7 +35,7 @@
</form>
<br>
<div id="FeedContainer">
@foreach ($data['posts'] as $post)
@foreach ($posts as $post)
<div class="FeedContainerBox" id="FeedContainerBox1">
<div class="FeedContainerBoxImageContainer" id="FeedContainerBox1ImageContainer">
<a href="{{ route('profile', $post->user->id) }}"><img alt="A image of {{ $post->user->name }}"
@ -46,25 +47,27 @@
<p id="FeedContainerBox1Text" style="word-wrap:break-word;max-width:400px">
"{{ $post->status }}"</p>
@if (!Auth::user()->settings->time_preference_24hr)
<p id="FeedContainerBox1Timestamp" alt="">{{ $post->created_at->format('F d, Y h:i A') }}</p>
<p id="FeedContainerBox1Timestamp" alt="">
{{ $post->created_at->format('F d, Y h:i A') }}</p>
@else
<p id="FeedContainerBox1Timestamp" alt="">{{ $post->created_at->format('F d, Y H:i') }}</p>
<p id="FeedContainerBox1Timestamp" alt="">
{{ $post->created_at->format('F d, Y H:i') }}</p>
@endif
</div>
</div>
@endforeach
@if ($data['posts']->isEmpty())
@if ($posts->isEmpty())
<p>Your feed is empty.</p>
@endif
</div>
{{ $data['posts']->links() }}
{{ $posts->links() }}
</div>
<div id="gamesframe">
<div class="content_special" style="justify-content: center;">
<h2>Friends ({{ Auth::user()->getFriendsCount() }})</h2>
@if (Auth::user()->getFriendsCount() > 0)
<a alt="View All, button" href="{{ route('friends') }}" style="margin-left: 5px"> <button class="bluebutton"
style="margin-top: 5px">View
<a alt="View All, button" href="{{ route('friends') }}" style="margin-left: 5px"> <button
class="bluebutton" style="margin-top: 5px">View
All</button></a>
@endif
</div>
@ -74,7 +77,7 @@
@if (Auth::user()->getFriendsCount() > 0)
<div id="profilefriendcontainer" class="content_special"
style="flex-wrap: wrap;justify-content: space-evenly;flex-direction: row;display: inline-flex;align-content: center;align-items: center;">
@foreach ($data['friends'] as $friend)
@foreach ($friends as $friend)
<div class="profilefriend">
<a href="{{ route('profile', $friend->id) }}"><img alt="Profile Image"
src="{{ asset('img/defaultrender.png') }}" width="150px" height="110px"></a>

View File

@ -1,18 +1,18 @@
@extends('layouts.app')
@section('title')
<title>{{ $data['user']->name }}'s Friends (Mutual) - {{ env('APP_NAME') }}</title>
<title>{{ $user->name }}'s Friends (Mutual) - {{ env('APP_NAME') }}</title>
@endsection
@section('content')
<h1 id="usernameframe">Your Mutual Friends with {{ $data['user']->name }} ({{ Auth::user()->getMutualFriendsCount($data['user']) }})</h1>
<a href="{{ route('profile_friends', $data['user']->id) }}" class="tab">All Friends</a>
<h1 id="usernameframe">Your Mutual Friends with {{ $user->name }} ({{ Auth::user()->getMutualFriendsCount($user) }})</h1>
<a href="{{ route('profile_friends', $user->id) }}" class="tab">All Friends</a>
@auth
<a href="#" class="tab_selected">Mutual Friends ({{ Auth::user()->getMutualFriendsCount($data['user']) }})</a>
<a href="#" class="tab_selected">Mutual Friends ({{ Auth::user()->getMutualFriendsCount($user) }})</a>
@endauth
<br>
<br>
<div class="content_special" id="FriendsContainer" style="flex-wrap: wrap;">
@foreach ($data['friends'] as $friend)
@foreach ($friends as $friend)
<div class="FriendsContainerBox" id="FriendsContainerBox1">
<div id="FriendsContainerBox1ImageContainer">
<a href="{{ route('profile', $friend->id) }}"><img alt="Profile Image"
@ -32,7 +32,7 @@
{{ Carbon\Carbon::parse($friend->last_seen)->diffForHumans() }}</strong>
@endif
<br>
@if (Auth::id() == $data['user']->id)
@if (Auth::id() == $user->id)
<form action="{{ route('friend_remove', $friend->id) }}" method="POST"
style="display:inline-block">
@csrf
@ -42,10 +42,10 @@
</div>
</div>
@endforeach
@if (!Auth::user()->getMutualFriendsCount($data['user']))
<p>You don't have any mutual friends with {{ $data['user']->name }}.</p>
@if (!Auth::user()->getMutualFriendsCount($user))
<p>You don't have any mutual friends with {{ $user->name }}.</p>
@endif
{{ $data['friends']->links() }}
{{ $friends->links() }}
</div>
<br>
@endsection

View File

@ -1,54 +1,54 @@
@extends('layouts.app')
@section('title')
<title>{{ $data['user']->name }} - {{ env('APP_NAME') }}</title>
<title>{{ $user->name }} - {{ env('APP_NAME') }}</title>
@endsection
@section('titlediscord')
<meta content="{{ $data['user']->name }} - {{ env('APP_NAME') }}" property="og:title" />
<meta content="{{ $user->name }} - {{ env('APP_NAME') }}" property="og:title" />
@endsection
@section('descdiscord')
<meta content="{{ $data['user']->blurb }} | ARCHBLOX is a work in progress revival." property="og:description" />
<meta content="{{ $user->blurb }} | ARCHBLOX is a work in progress revival." property="og:description" />
@endsection
@section('content')
<div id="profiletopcontainer">
<h1 id="usernameframe">{{ $data['user']->name }}</h1>
@if ($data['user']->settings->changed_name)
<h4>Previous Username: {{ $data['user']->settings->old_name }}</h4>
<h1 id="usernameframe">{{ $user->name }}</h1>
@if ($user->settings->changed_name)
<h4>Previous Username: {{ $user->settings->old_name }}</h4>
@endif
@if (Cache::has('is_online_' . $data['user']->id))
@if (Cache::has('is_online_' . $user->id))
<strong id="onlinestatus" class="onlinestatus_website">Website</strong>
@else
<strong id="onlinestatus" class="onlinestatus_offline">Offline - Last Online
{{ Carbon\Carbon::parse($data['user']->last_seen)->diffForHumans() }}</strong>
{{ Carbon\Carbon::parse($user->last_seen)->diffForHumans() }}</strong>
@endif
<br>
@if (!Auth::guest() && Auth::id() != $data['user']->id)
@if (Auth::user()->hasSentFriendRequestTo($data['user']))
@if (!Auth::guest() && Auth::id() != $user->id)
@if (Auth::user()->hasSentFriendRequestTo($user))
<button class="bluebutton" type="submit" disabled>Pending...</button>
@elseif (Auth::user()->hasFriendRequestFrom($data['user']))
<form action="{{ route('friend_handle', $data['user']->id) }}" method="POST">
@elseif (Auth::user()->hasFriendRequestFrom($user))
<form action="{{ route('friend_handle', $user->id) }}" method="POST">
@csrf
<button class="greenbutton" name="action" type="submit" value="accept">Accept</button>
<button class="redbutton" name="action" type="submit" value="decline">Decline</button>
</form>
@elseif (Auth::user()->isFriendWith($data['user']))
<form action="{{ route('friend_remove', $data['user']->id) }}" method="POST" style="display:inline-block">
@elseif (Auth::user()->isFriendWith($user))
<form action="{{ route('friend_remove', $user->id) }}" method="POST" style="display:inline-block">
@csrf
<button class="redbutton" type="submit">Unfriend</button>
</form>
@else
<form action="{{ route('friend_add', $data['user']->id) }}" method="POST" style="display:inline-block">
<form action="{{ route('friend_add', $user->id) }}" method="POST" style="display:inline-block">
@csrf
<button class="bluebutton" type="submit">Add Friend</button>
</form>
@endif
@switch($data['user']->settings->message_preference)
@switch($user->settings->message_preference)
@case(2)
<a href="/my/messages/compose?to={{ $data['user']->name }}"><button class="greybutton">Message</button></a>
<a href="/my/messages/compose?to={{ $user->name }}"><button class="greybutton">Message</button></a>
@break
@case(1)
@if (Auth::user()->isFriendWith($data['user']))
<a href="/my/messages/compose?to={{ $data['user']->name }}"><button class="greybutton">Message</button></a>
@if (Auth::user()->isFriendWith($user))
<a href="/my/messages/compose?to={{ $user->name }}"><button class="greybutton">Message</button></a>
@else
<a href="#"><button class="greybutton" disabled>Message (Friends Only)</button></a>
@endif
@ -60,8 +60,8 @@
</div>
<div class="content_special">
<div id="profileleftcontainer">
@if (!empty($data['user']->feedposts->last()->status))
<address id="status" style="word-wrap:break-word">"{{ $data['user']->feedposts->last()->status }}"
@if (!empty($user->feedposts->last()->status))
<address id="status" style="word-wrap:break-word">"{{ $user->feedposts->last()->status }}"
</address>
@else
<address id="status">"I'm new to ARCHBLOX!"</address>
@ -69,21 +69,21 @@
<img alt="profile image" src="{{ asset('img/defaultrender.png') }}" width="75%">
<div id="bio"
style="min-width:350px;max-width:350px;text-align:center;margin:0 auto;max-height:275px;overflow-y: auto;">
{!! nl2br(e($data['user']->blurb)) !!}</div>
{!! nl2br(e($user->blurb)) !!}</div>
<br>
<div id="stats">
@guest
<h3>Joined: {{ $data['user']->created_at->format('d/m/Y') }}</h3>
<h3>Joined: {{ $user->created_at->format('d/m/Y') }}</h3>
@else
<h3>Joined: {{ $data['user']->created_at->format(Auth::user()->settings->date_preference) }}</h3>
<h3>Joined: {{ $user->created_at->format(Auth::user()->settings->date_preference) }}</h3>
@endguest
<h3>Place Visits: 0</h3>
</div>
<br>
<h2>Role</h2>
<div style="white-space:nowrap">
@foreach ($data['badges'] as $badge)
@foreach ($data['user']->badges as $user_badge)
@foreach ($badges as $badge)
@foreach ($user->badges as $user_badge)
@if ($badge->id == $user_badge)
<div style="width:120px;display:inline-block">
<img src="/img/badges/{{ $badge->id }}.png" width="75px" height="75px" />
@ -107,19 +107,19 @@
<p>This user hasn't made any games yet!</p>
<br>
<div class="content_special" style="justify-content: center;">
<h2>Friends ({{ $data['user']->getFriendsCount() }})</h2>
@if ($data['user']->getFriendsCount() > 0)
<a href="{{ route('profile_friends', $data['user']->id) }}" style="margin-left: 5px"> <button
<h2>Friends ({{ $user->getFriendsCount() }})</h2>
@if ($user->getFriendsCount() > 0)
<a href="{{ route('profile_friends', $user->id) }}" style="margin-left: 5px"> <button
class="bluebutton" style="margin-top: 5px">View All</button></a>
</div>
@if (Auth::check() && Auth::id() != $data['user']->id && Auth::user()->getMutualFriendsCount($data['user']) > 0)
<a href="{{ route('mutual_friends', $data['user']->id) }}"
style="color:blue;font-size:12px">{{ Auth::user()->getMutualFriendsCount($data['user']) }} Mutual
@if (Auth::check() && Auth::id() != $user->id && Auth::user()->getMutualFriendsCount($user) > 0)
<a href="{{ route('mutual_friends', $user->id) }}"
style="color:blue;font-size:12px">{{ Auth::user()->getMutualFriendsCount($user) }} Mutual
Friends</a>
@endif
<div id="profilefriendcontainer" class="content_special"
style="flex-wrap: wrap;justify-content: space-evenly;flex-direction: row;display: inline-flex;align-content: center;align-items: center;">
@foreach ($data['friends'] as $friend)
@foreach ($friends as $friend)
<div class="profilefriend">
<a href="{{ route('profile', $friend->id) }}"><img alt="Profile Image"
src="{{ asset('img/defaultrender.png') }}" width="150px" height="110px"></a>

View File

@ -1,20 +1,20 @@
@extends('layouts.app')
@section('title')
<title>{{ $data['user']->name }}'s Friends - {{ env('APP_NAME') }}</title>
<title>{{ $user->name }}'s Friends - {{ env('APP_NAME') }}</title>
@endsection
@section('content')
<h1 id="usernameframe">{{ $data['user']->name }}'s Friends ({{ $data['user']->getFriendsCount() }})</h1>
<h1 id="usernameframe">{{ $user->name }}'s Friends ({{ $user->getFriendsCount() }})</h1>
<a href="#" class="tab_selected">All Friends</a>
@auth
@if ($data['user']->id != Auth::id())
<a href="{{ route('mutual_friends', $data['user']->id) }}" class="tab">Mutual Friends ({{ Auth::user()->getMutualFriendsCount($data['user']) }})</a>
@if ($user->id != Auth::id())
<a href="{{ route('mutual_friends', $user->id) }}" class="tab">Mutual Friends ({{ Auth::user()->getMutualFriendsCount($user) }})</a>
@endif
@endauth
<br>
<br>
<div class="content_special" id="FriendsContainer" style="flex-wrap: wrap;">
@foreach ($data['friends'] as $friend)
@foreach ($friends as $friend)
<div class="FriendsContainerBox" id="FriendsContainerBox1">
<div id="FriendsContainerBox1ImageContainer">
<a href="{{ route('profile', $friend->id) }}"><img alt="Profile Image"
@ -34,7 +34,7 @@
{{ Carbon\Carbon::parse($friend->last_seen)->diffForHumans() }}</strong>
@endif
<br>
@if (Auth::id() == $data['user']->id)
@if (Auth::id() == $user->id)
<form action="{{ route('friend_remove', $friend->id) }}" method="POST"
style="display:inline-block">
@csrf
@ -44,10 +44,10 @@
</div>
</div>
@endforeach
@if (!$data['user']->getFriendsCount())
<p>{{ $data['user']->name }} hasn't made friends with anyone yet.</p>
@if (!$user->getFriendsCount())
<p>{{ $user->name }} hasn't made friends with anyone yet.</p>
@endif
{{ $data['friends']->links() }}
{{ $friends->links() }}
</div>
<br>
@endsection