Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 6.8 PUT Method not working, Showing Blank Page

Laravel 6.8 PUT Method not working for one of Controller, Showing Blank Page

Any suggestion or solution are most welcome. Following are summery of code. Route Pointer is not going under Controller update function

HTML edit.blad.php ( I tested with {{ method_field('PUT') }} )

<form class="form-horizontal" action="{{ route('certificate.update',$certificate_data->id) }}" method="post">
    {{ csrf_field() }}
    <input type="hidden" name="_method" value="PUT">

    // Other Form Fields 

</form>

web.php ( Route File )

Route::group(['prefix' => 'admin'], function(){
    Route::resource('certificate', 'CertificateController');
});

php artisan route:list http://prntscr.com/qf662i

this is output of route:list

Controller Function

public function update(Request $request, Certificate $certificate)
{
        echo 'vvvvv'; 
        return $certificate;
        return $input = $request->all();

}

Pointer not coming into controller update and showing only blank page I also tested with all function into the controller

For reference -> If I change web.php and do following code then pointer is coming there. But not into Controller update function.

Route::put('certificate/{certificate}', function ($certificate) {
        return $certificate;
})->name('certificate_update');
like image 885
Viral Avatar asked Dec 24 '19 12:12

Viral


1 Answers

As per your code everything looks good.

  • You already tested PUT & PATCH variations as per expert suggestions here.
  • You can get pointer into route file (web.php) but not into controller's Any function >>> That means pointer is not passing to controller.

Reason for pointer not going into controller from route file

  • Your Path OR Name of controller is wrong / mismatched

  • Controller file is called from another place

Question

  • Any BACKUP FOLDER or BACKUP CONTROLLER files stored there into ?? [ \app\Http\Controllers\ ]

If answer is YES then it might be possible that wrong controller from backup is called from laravel cache. REMOVE Those backup files and Folders from controller folder.

Solution

I think controller PATH is cached and wrong controller is called instead. Try following commands to clear general cache.

php artisan cache:clear
php artisan route:cache
php artisan config:cache
php artisan view:clear

To clear controller file / path cache. We'll have to regenerate autoload.

Try following command. (This step is important)

composer dumpautoload

If this solves your issue then you can use normal html edit.blade form syntax as following.

<form action="{{ route('certificate.update',$certificate_data->id) }}" method="post">
       {{ csrf_field() }}
       {{ method_field('PUT') }}

       // Other form fields

</form> 

On your controller. Your normal code should work like following.

public function update(Request $request, Certificate $certificate)
{
    return $certificate;
}

Let me know if this process helps you. Good luck.

like image 58
Viral Avatar answered Oct 23 '22 10:10

Viral