Skip to content

Commit

Permalink
Added QuoteRequest with regex
Browse files Browse the repository at this point in the history
  • Loading branch information
perisicnikola37 committed Jul 5, 2022
1 parent fbc7b2e commit ca33d6d
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 19 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function store(UserRegisterRequest $request) {

auth()->attempt($request->only('email', 'password'));

return redirect()->route('dashboard');
return redirect()->route('home');

}

Expand Down
11 changes: 6 additions & 5 deletions app/Http/Controllers/QuoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Http\Requests\QuoteRequest;
use App\Models\Quote;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
Expand All @@ -15,15 +16,15 @@ public function index() {

}

public function store(Request $request) {
public function store(QuoteRequest $request) {

$input = $request->all();

// Using External Request
$this->validate($request, [
'author' => 'required',
'body' => 'required',
]);
// $this->validate($request, [
// 'author' => 'required',
// 'body' => 'required',
// ]);

// Quote::create([
// 'author' => $request->author,
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/PostRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function authorize()
public function rules()
{
return [
'body' => 'required|min:2|max:255',
'body' => 'required|min:10|max:255|regex:/^[a-zA-Z]+$/u',
];
}
}
31 changes: 31 additions & 0 deletions app/Http/Requests/QuoteRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class QuoteRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, mixed>
*/
public function rules()
{
return [
'author' => 'required|min:2|max:255|regex:/^[a-zA-Z]+$/u',
'body' => 'required|min:10|max:255|regex:/^[a-zA-Z]+$/u',
];
}
}
2 changes: 1 addition & 1 deletion resources/views/admin/quotes/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@section('content')

<div class="flex justify-center">
<div class="w-4/12 bg-white p-6 rounded-sm">
<div class="w-8/12 bg-white p-6 rounded-sm">

@if (session()->has('success-quote'))

Expand Down
7 changes: 4 additions & 3 deletions resources/views/components/post.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@props(['post' => $post])

<div class="mb-3">
<div class="mb-4">

<a href="{{route('users.posts', $post->user)}}" class="font-bold">

Expand All @@ -22,7 +22,7 @@
@method('DELETE')
<button
type="submit"
class="bg-red-500 hover:bg-red-700 text-white text-sm font-bold py-1 px-3 rounded">
class="mt-2 bg-red-500 hover:bg-red-700 text-white text-sm font-bold py-1 px-3 rounded">
Delete
</button>
</form>
Expand All @@ -32,7 +32,7 @@ class="bg-red-500 hover:bg-red-700 text-white text-sm font-bold py-1 px-3 rounde

{{-- @endif --}}

<div class="flex items-center">
<div class="flex">

@auth

Expand All @@ -54,6 +54,7 @@ class="bg-red-500 hover:bg-red-700 text-white text-sm font-bold py-1 px-3 rounde
@endif

@endauth


<span>{{$post->likes->count()}} {{Str::plural('like', $post->likes->count())}}</span>

Expand Down
2 changes: 1 addition & 1 deletion resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<div class="flex justify-center mt-5">

<img
class="rounded-lg"
class="rounded-lg mb-5"
src="https://cms-assets.tutsplus.com/cdn-cgi/image/width=850/uploads/users/988/posts/30254/image/website-homepage%20(1).jpg"
alt="">

Expand Down
18 changes: 18 additions & 0 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@
{{-- Tailwind --}}
<script src="https://cdn.tailwindcss.com"></script>

<style>
/* width */
::-webkit-scrollbar {
width: 6px;
}
/* Track */
::-webkit-scrollbar-track {
background: #f1f1f1;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: #6366F1;
}
</style>

</head>

<body class="bg-gray-200">
Expand Down
16 changes: 9 additions & 7 deletions resources/views/posts/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@section('content')

<div class="flex justify-center">
<div class="w-12/12 bg-white p-6 rounded-sm">
<div class="w-8/12 bg-white p-6 rounded-sm">


@if (session()->has('success-post'))
Expand Down Expand Up @@ -35,15 +35,17 @@
<p class="text-center mb-5 font-medium">Create post</p>

<label for="body" class="sr-only">Body</label>
<textarea name="body" id="body" cols="30" rows="4" class="bg-gray-100 border-2 w-full p-4 rounded-sm @error('body') border-red-500 @enderror" placeholder="Post something..."></textarea>

@error('body')

<div class="text-red-500 mt-2 text-sm">
{{$message}}
</div>

<p class="mb-2">{{$message}}</p>
@enderror
<textarea
name="body"
id="body"
cols="30"
rows="4"
class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline p-4 rounded-sm @error('body') border-red-500 @enderror" placeholder="Post something..."
value="{{old('body')}}"></textarea>

</div>

Expand Down

0 comments on commit ca33d6d

Please sign in to comment.