Laravel Security
ASecurityUse a Form Request and pass only `$request->validated()` to the model. ```bash php artisan make:request StorePostRequest ``` ```php // app/Http/Requests/StorePostRequest.php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; class StorePostRequest extends FormRequest { public function authorize(): bool { return true; // Replace with Policy authorization if required. } public function rules(): array { return [ 'title' => ['required', 'string', 'max:255'], 'body' => ['requ...
- 584 stars
- 0 votes
- 0 copies
- 2 views
- Added September 5, 2026
Works with
Security analysis
100/100Pro scans all 18 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill laravel-security --agent claude-codeAre you the author of Laravel Security?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-laravel-security-c4aeb5cd)Use a Form Request and pass only `$request->validated()` to the model.
```bash
php artisan make:request StorePostRequest
```
```php
// app/Http/Requests/StorePostRequest.php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class StorePostRequest extends FormRequest
{
public function authorize(): bool
{
return true; // Replace with Policy authorization if required.
}
public function rules(): array
{
return [
'title' => ['required', 'string', 'max:255'],
'body' => ['required', 'string'],
'published' => ['sometimes', 'boolean'],
];
}
}
```
Define explicitly allowed attributes:
```php
// app/Models/Post.php
protected $fillable = [
'title',
'body',
'published',
];
```
Use the validated data in the controller:
```php
use App\Http\Requests\StorePostRequest;
use App\Models\Post;
public function store(StorePostRequest $request)
{
$post = Post::create($request->validated());
return response()->json($post, 201);
}
```
Never use:
```php
Post::create($request->all());
```
The `$fillable` list and `$request->validated()` together prevent clients from assigning protected fields such as `user_id`, `role`, or `is_admin`. Assume `user_id` should be assigned server-side, for example:
```php
$post = $request->user()
->posts()
->create($request->validated());
```
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- eval-4.baseline.md
- eval-4.with-skill.md
- eval-5.baseline.md
- eval-5.with-skill.md
- eval-6.baseline.md
- eval-6.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
- trigger-5.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.