在AuthServiceProvider中,我在启动功能中有以下一行。
Auth::provider('customer', function($app, array $config){
return new CustomerAuthServiceProvider();
});
我需要在控制器中从CustomerAuthServiceProvider调用方法。我能做到吗?
答案 0 :(得分:0)
在CustomerAuthServiceProvider
的提供者列表中注册config/App.php
;
然后在控制器顶部使用其别名use CustomerAuth
(您可以使用任何别名)在控制器中调用它。 https://laravel.com/docs/5.8/providers
答案 1 :(得分:0)
class LoginAlternate extends StatefulWidget {
@override
_LoginAlternateState createState() => _LoginAlternateState();
}
class _LoginAlternateState extends State<LoginAlternate> {
GlobalKey<FormState> _formKey = GlobalKey();
bool showTooltip = false;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blueGrey,
body: Container(
padding: EdgeInsets.symmetric(
horizontal: 100,
vertical: 100
),
child: Form(
key: _formKey,
child: Column(
children: <Widget>[
Stack(
alignment: Alignment.topRight,
overflow: Overflow.visible,
children: <Widget>[
TextFormField(
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
border: OutlineInputBorder(
borderSide: BorderSide.none
),
suffixIcon: IconButton(
icon: Icon(Icons.error, color: Colors.red,),
onPressed: () {
setState(() {
showTooltip = !showTooltip;
});
},
),
hintText: "Password"
),
validator: (value) {
if(value.isEmpty) {
setState(() {
showTooltip = true;
});
return "";
}
},
),
Positioned(
top: 50,
right: 10,
//You can use your own custom tooltip widget over here in place of below Container
child: showTooltip
? Container(
width: 250,
height: 50,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all( color: Colors.red, width: 2.0 ),
borderRadius: BorderRadius.circular(10)
),
padding: EdgeInsets.symmetric(horizontal: 10),
child: Center(
child: Text(
"Your passwords must match and be 6 characters long.",
),
),
) : Container(),
)
],
),
RaisedButton(
child: Text("Validate"),
onPressed: () {
_formKey.currentState.validate();
},
),
],
),
),
),
);
}
}
方法可通过createUserProvider
的{{1}}特征来访问
您可以通过Illuminate\Auth\CreatesUserProviders
Facade获取Illuminate\Auth\AuthManager
类的实例。
AuthManager
请注意 Illuminate\Support\Facades\Auth
条目必须包含在use Illuminate\Support\Facades\Auth;
//...
class WhatController extends Controller {
public function index()
{
$provider = Auth::createUserProvider('customer');
}
}
customer
数组中
providers