控制器內容如下
<?php
namespace App\Http\Controllers\platform;
//use Illuminate\Http\Request;
use App\Http\Requests\AuthRequest;
use App\Http\Controllers\Controller;
use Auth;
class SessionsController extends Controller
{
/**
* 使用者登入(平臺使用者登陸)
* @param AuthRequest $request
*/
public function store(AuthRequest $request)
{
$credentials = array(
'email' => $request->email,
'password' => $request->password,
);
if (Auth::guard('platformAdmin')->attempt($credentials)){
//登入成功
return Auth::guard('platformAdmin')->user();
} else {
//登入失敗
return '登入失敗';
}
}
}
請求類檔案如下:
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class AuthRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'email' => ['required', 'email', 'max:255'],
'password' => ['required'],
];
}
public function attributes()
{
return [
'email' => '郵箱',
'password' => '密碼',
];
}
public function messages()
{
return [
'email.required'=>'請填寫郵箱',
'email.email'=>'郵箱格式錯誤',
'password.required' => '密碼不能為空'
];
}
}
但是生成的文件沒有引數說明,請賜教
本作品採用《CC 協議》,轉載必須註明作者和本文連結