Skip to content

Commit

Permalink
all tests passed
Browse files Browse the repository at this point in the history
  • Loading branch information
exe544 committed Oct 20, 2023
1 parent 8f62e93 commit dd019e4
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/BuildingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function create()
// TASK: Customize the validation error message to say "Please enter the name"
public function store(StoreBuildingRequest $request)
{
Building::create($validator->validated());
Building::create($request->validated());

return 'Success';
}
Expand Down
6 changes: 4 additions & 2 deletions app/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ class PostController extends Controller
{
public function store(Request $request)
{
$request->validate(
$request->validate([
// ... TASK: write validation here so that "title" field
// would be required and unique in the "posts" DB table
);
'title' => ['required', 'unique:posts'],

]);

// Saving the post
Post::create(['title' => $request->title]);
Expand Down
3 changes: 3 additions & 0 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public function update(Request $request)
// <input name="profile[name]" ... />
// <input name="profile[email]" ... />
// Write validation rules, so both name and email are required
'profile.name' => 'required',
'profile.email' => 'required',

]);

auth()->user()->update($request->profile ?? []);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function update(User $user, UpdateUserRequest $request)
{
// TASK: change this line to not allow is_admin field to be updated
// Update only the fields that are validated in UpdateUserRequest
$user->update($request->all());
$user->update($request->except('is_admin'));

return 'Success';
}
Expand Down
5 changes: 5 additions & 0 deletions app/Http/Requests/StoreBuildingRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ public function rules()
'name' => 'required'
];
}

public function messages()
{
return ['name.required' => 'Please enter the name'];
}
}
30 changes: 30 additions & 0 deletions app/Http/Requests/StoreItemRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

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

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
*/
public function rules(): array
{
return [
'name' => 'required',
'description' => 'required',

];
}
}
22 changes: 22 additions & 0 deletions app/Rules/Uppercase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;

class Uppercase implements ValidationRule
{
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if ($value !== ucfirst($value))
{
$fail('The title does not start with an uppercased letter');
}
}
}
4 changes: 3 additions & 1 deletion resources/views/products/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
<br />
{{-- TASK: show the validation error for the specific "name" field --}}
{{-- using one Blade directive: pseudo-code below --}}
{{-- @directive --}}
@error('name')
{{$message}}
@enderror
{{-- {{ $message }} --}}
{{-- @endDirective --}}
<br /><br />
Expand Down
8 changes: 8 additions & 0 deletions resources/views/projects/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

<form method="POST" action="{{ route('projects.store') }}">
@csrf
@if($errors->any())
@foreach($errors->all() as $error)
<ul>
<li>{{ $error }}</li>
</ul>
@endforeach
<br />
Title:
<br />
<input type="text" name="title" />
Expand All @@ -15,4 +22,5 @@
<input type="text" name="description" />
<br /><br />
<button type="submit">Save</button>
@endif
</form>
2 changes: 1 addition & 1 deletion resources/views/teams/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Name:
<br />
{{-- TASK: change this field so it would contain old value after validation error --}}
<input type="text" name="name" />
<input type="text" name="name" value="{{ old('name') }}"/>
<br /><br />
<button type="submit">Save</button>
</form>

0 comments on commit dd019e4

Please sign in to comment.