Reputation: 31
I am pretty new to laravel, and have searched everywhere but could not fix this error:
Argument 1 passed to InsertController::insert() must be an instance of Illuminate\Http\Request, none given
I am trying to validate my input by passing in the Request method so I don't have to re-write a new validate method for every form, but it seems to always give me this error.
<?php
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
class InsertController extends Controller {
public function insert(Request $request) {
$username = Input::get('username');
$pw = Hash::make(Input::get('pw'));
$email = Input::get('email');
$this->validate($request, ['name' => 'required|unique:users',
'password' => 'required|min:8|max:255',
'email' => 'required|email|unique:users']);
if(!$validator->fails()) {
$user = DB::table('users')->insert(
['email' => $email, 'password' => $pw, 'name' => $username]);
}
}
}
Here is the route I'm calling it with as well.
Route::post('users', ['uses' => 'InsertController@insert', 'before' => 'csrf'], function()
{
$users = User::all(); //call the User model for all data in users table
return View::make('users')->with('users', $users);
});
Upvotes: 1
Views: 12181
Reputation: 1083
The reason why it is not working is because of the given code relays on the injection of Request-Object, which was introduced with Laravel 5 but the installed framework version is 4.2.17.
To solve the issue you can remove the Request-Object from the method signature or update Laravel to 5.
Upvotes: 4