Answers for "file validation in laravel 8"

PHP
2

request validate file laravel

$validated = $request->validated();

use this:

    public function createAccount(RegisterRequest $request)
    {
        $attr = $request->validated();

instead of :

    public function createAccount(Request $request)
    {
        $attr = $request->validate([
            'name' => 'required|string|max:255',
            'email' => 'required|string|email|unique:users,email',
            'password' => 'required|string|min:6|confirmed'
        ]);


php artisan make:request RegisterRequest

    public function rules()
    {
        return [
            'name' => 'required|string|max:255',
            'email' => 'required|string|email|unique:users,email',
            'password' => 'required|string|min:6|confirmed'
        ];
    }
Posted by: Guest on September-22-2021
1

laravel validate file type

'image' => 'required|mimes:jpeg'
//or
'image' => 'required|image'
Posted by: Guest on June-23-2021
4

laravel validation

/**
 * Store a new blog post.
 *
 * @param  Request  $request
 * @return Response
 */
public function store(Request $request)
{
    $validatedData = $request->validate([
        'title' => 'required|unique:posts|max:255',
        'body' => 'required',
    ]);

    // The blog post is valid...
}
Posted by: Guest on October-19-2020

Browse Popular Code Answers by Language