在数据库中,我有一个表last_login_at列的用户.每当有一些用户登录时 - 我想提升last_login_at.
所以,我创建了app/Listeners/UpdateLastLoginOnLogin.php:
namespace App\Listeners;
use Carbon\Carbon;
class UpdateLastLoginOnLogin
{
public function handle($user, $remember)
{
$user->last_login_at = Carbon::now();
$user->save();
}
}
Run Code Online (Sandbox Code Playgroud)
在app/Providers/EventServiceProvider中:
protected $listen = [
'auth.login' => [
'App\Listeners\UpdateLastLoginOnLogin',
],
];
Run Code Online (Sandbox Code Playgroud)
但这不起作用,事件未得到处理.这里已经提到了同样的问题:Laravel 5.2登录但没有解决方案的EventServiceProvider映射.我试过这样做:
...
use Illuminate\Auth\Events\Login;
class UpdateLastLoginOnLogin
{
public function handle(Login $event)
{
$event->user->last_login_at = Carbon::now();
$event->user->save();
}
}
Run Code Online (Sandbox Code Playgroud)
和:
protected $listen = [
'Illuminate\Auth\Events\Login' => [
'App\Listeners\UpdateLastLoginOnLogin',
],
];
Run Code Online (Sandbox Code Playgroud)
但它不起作用.
另外,我检查了这个:https://laracasts.com/discuss/channels/general-discussion/login-event-handling-in-laravel-5但是php artiasn clear-compiled …
我在数据库中有文章模型和文章表。每篇文章可以使用Laravel的标准URI结构来示出:www.example.com/articles/5(其中,5是文章id)。每篇文章都有一个slug字段(articles表中的slug列),因此我使用Route Model Bindingslug代替id:
RouteServiceProvider.php:
public function boot(Router $router)
{
parent::boot($router);
\Route::bind('articles', function($slug) {
return \App\Article::where('slug', $slug)->firstOrFail();
});
}
Run Code Online (Sandbox Code Playgroud)
在routes.php中,我有:
Route::resource('articles', 'ArticleController');
Run Code Online (Sandbox Code Playgroud)
现在可以使用以下网址访问文章:www.example.com/some_slug。
但是现在,当我要编辑某些文章时,出现以下错误:
没有有关模型[App \ Article]的查询结果。
例如,当我尝试打开以下代码时:www.example.com/some_slug/edit-我收到该错误。
因此,方法ArticleController @ show(Article $ article)可以正常工作,但是ArticleController @ edit(Article $ article)不起作用。
这是我的路线清单:
这是ArticleController的显示和编辑方法:
public function show(Article $article) // THIS WORKS FINE
{
$tags = $article->tags()->get();
return view('articles.show', compact('article', 'tags'));
} …Run Code Online (Sandbox Code Playgroud) 在我的composer.json我
"require": {
. . .
"unisharp/laravel-filemanager": "~1.8"
}
Run Code Online (Sandbox Code Playgroud)
目前,最新版本是v1.8.2.2,运行composer update命令后我将它安装在我的localhost项目上(一切正常).
我已将local(git push origin master)从localhost 推送到Bitbucket上的远程仓库,并通过SSH连接到Web服务器并git clone ...从远程仓库克隆()它.
现在,当我运行composer update(在Web服务器上) - 它安装v1.8.0,它有一些bug.在那之后,当我再次尝试跑composer update- 我得到:
Nothing to install or update
Run Code Online (Sandbox Code Playgroud)
...但它仍然是v1.8.0(不像v1.8.2.2那样在localhost上).
所以,我在本地主机和实时服务器上使用相同的composer.json相同的项目,但由于某种原因,localhost有最新版本的软件包,而实时版本的旧版本有bug并且composer update不更新它.
你知道为什么会这样吗?我该怎么解决?
在TinyMCE的代码(源代码)编辑器中,当我想用类添加一些span或i元素时(例如,当我想添加Font Awesome图标时) - TinyMCE删除了类.例如,如果我想添加:
<span class="fa fa-university"></span>
Run Code Online (Sandbox Code Playgroud)
最后我会:
<span></span>
Run Code Online (Sandbox Code Playgroud)
此外,在源代码编辑器中我尝试添加<i class="fa fa-university"></i>但问题是相同的 - 类被TinyMCE(<i></i>)删除.
我正在使用TinyMCE v4.4.1,这些是我的设置:
tinymce.init({
selector: '#body',
height: 500,
theme: 'modern',
plugins: [
'advlist autolink lists link image charmap preview hr anchor pagebreak',
'searchreplace wordcount visualblocks visualchars code fullscreen',
'insertdatetime media nonbreaking save table contextmenu directionality',
'emoticons template paste textcolor colorpicker textpattern codesample fontawesome noneditable'
],
toolbar1: 'insertfile undo redo | formatselect fontselect fontsizeselect fontawesome',
toolbar2: 'bold italic underline strikethrough …Run Code Online (Sandbox Code Playgroud) 我正在使用 Select2 和 Ajax 来加载远程数据(建议)。
一切正常,但有一个问题:当用户只输入空格(按空格键)时 - 正在发送 Ajax 请求。
我怎样才能防止这种情况?另外,我想在发送之前修剪条款。
$(".js-data-example-ajax").select2({
placeholder: "Select... ",
minimumInputLength: 3,
ajax: {
url: "/my-site/tags",
dataType: 'json',
data: function (params) {
return {
q: params.term
};
},
processResults: function (data) {
return {
results: data
};
},
cache: true
}
Run Code Online (Sandbox Code Playgroud)
编辑:
我忘了提到我已经尝试过这样的事情:
data: function (params) {
if (params.term.trim().length < 2) {
return;
}
return {
q: $.trim(params.term)
};
},
Run Code Online (Sandbox Code Playgroud)
并且仍然发送 GET (Ajax) 请求。
我正在使用Laravel 5.4,并且具有以下关系:
hasMany主题(threads())hasMany发布(posts())belongsTo用户(user())belongsTo使用者(user())目前,我ThreadsController@index的个人资料如下:
public function index()
{
$threads = $this->forum->threads()
->approved()
->withCount(['posts AS approved_replies' => function ($query) {
$query->where('posts.approved', true)->where('posts.is_starting_thread', false);
}])
->with(['posts' => function ($query) { // Posts
$query->approved()
->with('user') // Author of post
->latest();
}]
)
->with('user') // Author of thread
->latest()
->paginate(20);
return view('forums.threads.index')->with([
'forum' => $this->forum, 'threads' => $threads
]);
}
Run Code Online (Sandbox Code Playgroud)
我index.blade.php应显示 …
有一个articles数据库表(和Article模型),其中包含以下 3 列:
col_1col_2col_3如何选择这三列不 NULL 同时的所有文章?
因此,如果col_1 = NULL和- 不要选择(包含)这些文章col_2 = NULL。col_3 = NULL但如果这些列中的一列或多列不是NULL- 则选择(包含)它。
其查询生成器如下所示:
Article::select('articles.*')-> ... ->get();
Run Code Online (Sandbox Code Playgroud)
当然,取而代之的...是检查所有这 3 列是否同时不为空。
我知道这是错误的:
Article::select('articles.*')
->whereNotNull('col_1')
->whereNotNull('col_2')
->whereNotNull('col_3')
->get();
Run Code Online (Sandbox Code Playgroud)
...因为它不会选择(包含)其中一篇为 NULL ( col_1) 且其余 (col_2和col_3) 不为 NULL 的文章。
- - - - - - - - - 更新: - - - - - - - …