Skip to content

Commit

Permalink
Redesign of front page
Browse files Browse the repository at this point in the history
  • Loading branch information
coolbigbear committed Dec 20, 2019
1 parent 7a265aa commit 1597a17
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 172 deletions.
2 changes: 1 addition & 1 deletion imgbook/app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class LoginController extends Controller
*
* @var string
*/
protected $redirectTo = '/home';
protected $redirectTo = '/';

/**
* Create a new controller instance.
Expand Down
41 changes: 35 additions & 6 deletions imgbook/app/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Profanity;
use App\Comment;
use App\Post;
use App\Tag;

class PostController extends Controller
{
Expand All @@ -17,13 +18,15 @@ function validateRequest($request) {
'title' => 'required|max:255',
'image' => 'required|image|mimes:jpeg,png,jpg',
'description' => 'nullable|max:500',
'checkbox' => 'nullable',
]);
}

function validateUpdateRequest($request) {
return $validatedData = $request->validate([
'title' => 'required|max:255',
'description' => 'nullable|max:500',
'checkbox' => 'nullable',
]);
}

Expand All @@ -46,7 +49,8 @@ public function index()
*/
public function create()
{
return view('posts.create', ['update' => false]);
$tags = Tag::orderBy('tag', 'asc')->get();
return view('posts.create', ['update' => false, 'tags' => $tags]);
}

/**
Expand All @@ -58,7 +62,7 @@ public function create()
public function store(Request $request, Profanity $p)
{
$validatedData = $this->validateRequest($request);

$profanity = $p->checkProfanity($validatedData['title'].$validatedData['description']);

$profanity = (string) $profanity->getBody();
Expand All @@ -76,19 +80,29 @@ public function store(Request $request, Profanity $p)
}

$image = $validatedData['image'];

$tags = [];

if (sizeOf($validatedData['checkbox']) != 0) {
$checkboxes = $validatedData['checkbox'];
for ($i=0; $i < 10; $i++) {
if(array_key_exists($i, $checkboxes)) {
array_push($tags, $i);
}

}
}

$a = new Post;
$a->title = $validatedData['title'];
$a->description = $validatedData['description'];
$a->user_id = Auth::user()->id;
$a->tags()->attach($tags);
$a->save();

\App::call('App\Http\Controllers\ImageController@store', ['image' => $image, 'post_id' => $a->id]);

session()->flash('message', 'Post created');

return redirect()->route('posts.index');

}

/**
Expand All @@ -115,8 +129,9 @@ public function show($id)
public function edit(Request $request, $id)
{
$post = Post::findOrFail($id);
$tags = Tag::All();
if($post->user_id == Auth::user()->id) {
return view('posts.create', ['update' => true, 'post' => $post]);
return view('posts.create', ['update' => true, 'post' => $post, 'tags' => $tags]);
} else {

session()->flash('message', 'Unauthorized');
Expand Down Expand Up @@ -153,8 +168,22 @@ public function update(Request $request, $id, Profanity $p)
return view('posts.create', ['update' => true, 'post' => $post])->withErrors($errors);
}

$tags = [];

if (isset($request['checkbox'])) {
$checkboxes = $request['checkbox'];
for ($i=0; $i < 10; $i++) {
if(array_key_exists($i, $checkboxes)) {
array_push($tags, $i);
}

}
}

$post->title = $request['title'];
$post->description = $request['description'];
$post->tags()->detach();
$post->tags()->attach($tags);
$post->save();
$userId = Auth::user()->id;

Expand Down
96 changes: 52 additions & 44 deletions imgbook/resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
Expand All @@ -19,7 +20,8 @@
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>

<body>
<div id="app">
<nav class="navbar sticky-top navbar-light bg-white shadow-sm">
<div class="container">
Expand All @@ -28,13 +30,15 @@
{{ config('app.name', 'ImgBook') }}
</a>
@auth
<form class="form-inline" method="GET" action="{{ route('posts.create') }}">
@csrf
<button class="btn btn-sm btn-primary" type="submit">New Post</button>
</form>
<form class="form-inline" method="GET" action="{{ route('posts.create') }}">
@csrf
<button class="btn btn-sm btn-primary" type="submit">New Post</button>
</form>
@endauth
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
<button class="navbar-toggler" type="button" data-toggle="collapse"
data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false"
aria-label="{{ __('Toggle navigation') }}">
<span class="navbar-toggler-icon"></span>
</button>

Expand All @@ -48,32 +52,35 @@
<ul class="navbar-nav ml-auto">
<!-- Authentication Links -->
@guest
<li class="nav-item">
<a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
</li>
@if (Route::has('register'))
<li class="nav-item">
<a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
</li>
@endif
<li class="nav-item">
<a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
</li>
@if (Route::has('register'))
<li class="nav-item">
<a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</a>
</li>
@endif
@else
<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
{{ Auth::user()->name }} <span class="caret"></span>
</a>

<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="event.preventDefault();

<li class="nav-item dropdown">
<a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
{{ Auth::user()->name }} <span class="caret"></span>
</a>

<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('logout') }}" onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
{{ __('Logout') }}
</a>

<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
@csrf
</form>
</div>
</li>
{{ __('Logout') }}
</a>

<form id="logout-form" action="{{ route('logout') }}" method="POST"
style="display: none;">
@csrf
</form>
</div>
</li>
@endguest
</ul>
</div>
Expand All @@ -86,22 +93,22 @@
<h1>@yield('title')</h1>
@yield('back')
@if (session('message'))
<div>&nbsp;</div> {{-- add single space --}}
<div class="alert alert-success alert-dismissible">
<b>{{ session('message')}}</b>
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
</div>
<div>&nbsp;</div> {{-- add single space --}}
<div class="alert alert-success alert-dismissible">
<b>{{ session('message')}}</b>
<a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
</div>
@endif
@if ($errors->any())
<div>&nbsp;</div> {{-- add single space --}}
<div class="alert alert-danger">
<strong>Errors:</strong>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error}}</li>
@endforeach
</ul>
</div>
<div>&nbsp;</div> {{-- add single space --}}
<div class="alert alert-danger">
<strong>Errors:</strong>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error}}</li>
@endforeach
</ul>
</div>
@endif
</div>
</div>
Expand All @@ -110,4 +117,5 @@
</main>
</div>
</body>
</html>

</html>
30 changes: 0 additions & 30 deletions imgbook/resources/views/layouts/oldapp.blade.php

This file was deleted.

Loading

0 comments on commit 1597a17

Please sign in to comment.