dipcb05's avatar

laravel form redirect to same page after submit

trying to updating profile using patch. but after submit, it come to same route controller

 public function update()
    {
        $data = request()->validate([
            'name' => 'required',
            'country' => 'required',
            'bdate' => '',
            'job' => 'required',
            'wy' => '',
            'description' => '',
            'website' => 'url',
            'pic' => '',
        ]);
        if(request('pic'));
        {
            $pic = request('pic')->store('upload/pro_pic', 'public');
            $pic2 = ['dd' => $pic];
        }
        dd($data);

    }

view

   <div class="card-body">
                        <form action ="{{ route('profile.update') }}"
                              enctype="multipart/form-data"
                              method="post">
                            @csrf
                            @method('PATCH')
......................

in web.php, this particular route -

Route::patch('/edit', 'ProfileController@update')->name('profile.update');
0 likes
2 replies
Sergiu17's avatar
Sergiu17
Best Answer
Level 60

If validation fails, then Laravel redirects back,

@if($errors->has())
   @foreach ($errors->all() as $error)
      <div>{{ $error }}</div>
  @endforeach
@endif
dipcb05's avatar

thanks, after removing validation , it works.

Please or to participate in this conversation.