Home > Back-end >  Validation only partial working using laravel 8
Validation only partial working using laravel 8

Time:10-27

I'm using Laravel 8. I'm having trouble getting my validation to work. Only the image seems to work. I can't update any of the input fields except image. Can anyone help me fix my code? here's part of the code

public function editPage(request $request)
{
    
$request->validate([
    'image' => 'required|mimes:jpeg,jpg,png|max:100',
    'pageName' => 'required',
    'pageColor' => 'required',
    'pageFontcolor' => 'required',
    'pageDescription' => 'required',
    'pagePixiv' => 'required',
    ]);
    
    $userId = Auth::user()->id;
    $littlelink_name = Auth::user()->littlelink_name;

    $profilePhoto = $request->file('image');
    $pageName = $request->pageName;
    $pageColor = $request->pageColor;
    $pageFontcolor = $request->pageFontcolor;
    $pageDescription = $request->pageDescription;
    $pagePixiv = $request->pagePixiv;
    
    User::where('id', $userId)->update(['littlelink_name' => $pageName, 'littlelink_color' => $pageColor, 'littlelink_fontcolor' => $pageFontcolor, 'littlelink_pixiv' => $pagePixiv, 'littlelink_description' => $pageDescription]);

    if(!empty($profilePhoto)){
    $profilePhoto->move(public_path('/img'), $littlelink_name . ".png");
    }

    return back()->with('message', 'Saved');
}

CodePudding user response:

You should use input() function to get a single field inside the request.

$pageName = $request->input('pageName');

Otherwise you can use the all() method which returns all data in request

$data = $request->all();

Laravel request docs

  • Related