我只是想向表单添加操作,我尝试如下:
{{ Form::open(['action'=> ['AuthController@login'], 'method'=>"POST",'class'=>'login-form']) }}
但是我遇到以下错误:
Action App\Http\Controllers\AuthController@login not defined. (View: D:\server\htdocs\PMS\resources\views\custom_auth\login.blade.php)
我配置laravel集体HTML。我的代码有什么问题?
更新:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Validator;
use Auth;
class AuthController extends Controller
{
function show(){
return view('custom_auth.login');
}
public function login(Request $request){
print_r($request); exit;
$this->validate($request,[
'email' => 'required|email',
'password' => 'required|alphaNum|min:3'
]);
$user_data = array(
'email' => $request->get('email'),
'password' => $request->get('password')
);
if(Auth::attempt($user_data)){
return redirect('/dashboard');
}else{
return back()->with('error','Wrong Credential');
}
}
}
答案 0 :(得分:1)
使用Form
帮助程序时,您无需将操作放入数组中,因此请尝试:
{{ Form::open(['action'=> 'AuthController@login', 'method'=>"POST",'class'=>'login-form']) }}
当然,请确保public
中存在login()
AuthController
方法
此外,不要忘记将其添加到您的路由文件routes/web.php
:
Route::post('login', 'AuthController@login');
我希望对您有帮助