Skip to content

Commit

Permalink
coba
Browse files Browse the repository at this point in the history
  • Loading branch information
FahryIbrahim authored Sep 1, 2024
1 parent 8f62e93 commit 38fbce3
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 6 deletions.
1 change: 1 addition & 0 deletions app/Http/Controllers/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public function store(Request $request)
$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
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ 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->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'
]
}
}
34 changes: 34 additions & 0 deletions app/Http/Requests/StoreItemRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

// TASK: Customize the validation error message to say "Please enter the name"
class StoreItemRequest extends FormRequest
{
protected $redirectRoute = 'buildings.create';

/**
* 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
*/
public function rules()
{
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
{
$firstLetter = $value[0];
if (strtoupper($firstLetter) !== $firstLetter) {
$fail('The :attribute does not start with an uppercased letter');
}
}
}
3 changes: 3 additions & 0 deletions resources/views/products/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
{{-- @directive --}}
{{-- {{ $message }} --}}
{{-- @endDirective --}}
@error('name')
<div class="alert alert-danger">{{ $message }}</div>
@enderror
<br /><br />
<button type="submit">Save</button>
</form>
6 changes: 2 additions & 4 deletions resources/views/projects/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
@csrf
Title:
<br />
<input type="text" name="title" />
<br /><br />
<input type="text" name="title" oninvalid="alert('The name field is required.');" required/> <br /><br />
Description:
<br />
<input type="text" name="description" />
<br /><br />
<input type="text" name="description" oninvalid="alert('The description field is required.');" required /> <br /><br />
<button type="submit">Save</button>
</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 38fbce3

Please sign in to comment.