我发现理解 Facades 有点困难。特别是如何从外观名称中找到底层类名称/位置。我已经阅读了文档,但仍然不清楚。比如在使用的时候Auth::login()
,发现Auth Facade里面没有login()方法。
class Auth extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'auth';
}
/**
* Register the typical authentication routes for an application.
*
* @return void
*/
public static function routes()
{
static::$app->make('router')->auth();
}
}
Run Code Online (Sandbox Code Playgroud)
该验证外墙getFacadeAccessor()方法返回一个字符串权威性。但是auth我应该看哪个班级?如何解析实际的类?
谢谢,
我正在创建一个Reply模型,然后尝试返回具有所有者关系的对象。这是返回空对象的代码:
//file: Thread.php
//this returns an empty object !!??
public function addReply($reply)
{
$new_reply = $this->replies()->create($reply);
return $new_reply->with('owner');
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我将with()方法换成load()方法以加载所有者关系,则可以得到预期的结果。那就是返回的回复对象及其相关的所有者关系:
//this works
{
$new_reply = $this->replies()->create($reply);
return $new_reply->load('owner');
}
Run Code Online (Sandbox Code Playgroud)
我不明白为什么。寻找澄清。
谢谢,耶
我无法捕获我从控制台发出的自定义组件上的flash事件.这是我的组件:
/* file flash.vue */
<template>
<span :class="type" class="alert flash-alert" v-show="show">
{{ body }}
</span>
</template>
<script>
export default {
props: ['type','message'],
data() {
return {
body: this.message,
show: false,
};
},
created() {
if(this.body)
{
this.showComp();
this.hide();
}
},
methods: {
showComp: function(){
this.show = true;
},
hide: function()
{
var vm = this;
setTimeout(function() {
vm.show = false;
},2000);
},
},
events: {
flash: function(newMessage) {
this.body = newMessage;
this.showComp();
},
}
}
Run Code Online (Sandbox Code Playgroud)
在Chrome控制台上,我用以下方法解雇了这个事件:
/* from …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 vee-validate 3。版本 3 发生了很多变化。问题是错误消息没有特定的字段名称。以下是我在 laravel Blade 文件中的代码:
<validation-provider rules="email" v-slot="{ errors }">
<input type="text"
class="input"
name="email"
v-model="email">
<span>@{{ errors[0] }}</span>
</validation-provider>
Run Code Online (Sandbox Code Playgroud)
当我开始在输入字段中输入时,错误消息会打印在跨度标记内,但它没有字段名称,而是一个通用的“字段”,如下所示:
{field} is not valid.
有人知道如何让它工作吗?
谢谢,
我可能正在做一些非常愚蠢的事情。不小心产生了一段代码,我似乎无法弄清楚它是如何工作的。
我正在尝试自定义未经身份验证的用户重定向到登录页面。因此,当用户尝试访问受保护的页面时,laravel 会将用户重定向到登录页面。在这种情况下,我试图显示 Javascript toastr 消息。
我所做的是自定义类中的unauthenticated方法App\Exceptions\Handler.php如下:
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
//dd($request);
return redirect()->guest('login')->withError('You are not logged in or Your session has expired');
}
Run Code Online (Sandbox Code Playgroud)
请注意,我错过s了withError函数中的 。在我的刀片文件中,我显示的 toastr 通知如下:
<script>
@if(Session::has('error'))
toastr.error("{{Session::get('error')}}");
@endif
</script>
Run Code Online (Sandbox Code Playgroud)
因此,每当用户因为尚未登录而被重定向到登录页面时,就会显示 Java Script toastr 消息。但是,我无法弄清楚该Session('error')函数是如何填充该值的withError。我只能发现 Laravel 有withErrors函数,没有withError.
试图在过去几个小时内排除故障,但运气不佳。在这里寻求一些指导。谢谢。顺便说一句,我对 Laravel 很陌生。
laravel-5.4 ×2
php ×2
eloquent ×1
events ×1
javascript ×1
laravel ×1
laravel-5 ×1
vee-validate ×1
vuejs2 ×1