Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass tests #281

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/Http/Controllers/ItemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public function store(StoreItemRequest $request)
return 'Success';
}



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

// 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 @@ -9,6 +9,9 @@ class ProfileController extends Controller
public function update(Request $request)
{
$request->validate([

'profile.name' => 'required|string',
'profile.email' => 'required|email'
// TASK: imagine that in the Blade the fields are
// <input name="profile[name]" ... />
// <input name="profile[email]" ... />
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->validated());

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

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

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreItemRequest extends FormRequest
{

public function authorize(): bool
{
return true;
}

public function rules(): array
{
return [
'name' => 'required',
'description' => 'required',
];
}
}
21 changes: 21 additions & 0 deletions app/Rules/Uppercase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?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 (ord($value[0]) > 90) {
$fail('The title does not start with an uppercased letter');
}
}
}
Loading
Loading