0

I'm using Xampp and Laravel and my app is throwing the following error while I'm trying to make a post route:

ERROR

Declaration of App\Http\Controllers\HandleClient::validate() should be compatible with App\Http\Controllers\Controller::validate(Illuminate\Http\Request $request, array $rules, array $messages = Array, array $customAttributes = Array)

Form

<form action="{{route('handle')}}" method="POST">
    <label for="cn">Customer Name</label>
    <input type="text" name="cn" placeholder="Customer Name" />
    <input type="submit" value="Add Request"/>
    <input type="hidden" value="{{Session::token()}}" name="_token" />
</form>

Controller HandleClient.php:

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;

class HandleClient extends Controller
{       
    public function validate(Request $request){
        return view('finish',$request);
    }   
}

web.php routes file:

<?php
Route::get('/', function () {
    return view('welcome');
})->name('home');
Route::post('/Request_handled',[
    'uses'  => 'HandleClient@validate',
    'as'    => 'handle'
]);

1 Answer 1

1

By default, the base Controller class usesValidatesRequests which provides a validate function to the Controller class. Naming your function validate overrides this function.

Rename your function from validate to something else and update your route, then you shouldn't have a conflict anymore.

2
  • that helped already,, but I got this error after this solution {Undefined property: Illuminate\View\Factory::$startSection}
    – Poula Adel
    Apr 21, 2018 at 9:12
  • 1
    Can you show us the blade file for your view called "finish"?
    – S. Dev
    Apr 21, 2018 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.