我做这样的门:
Gate::define('update-post', function ($user, Post $post) {
return $user->hasAccess(['update-post']) or $user->id == $post->user_id;
});
Run Code Online (Sandbox Code Playgroud)
我检查了我的数据库,它有更新帖子访问权限,用户ID与帖子相同.但我得到了:
此操作未经授权.
错误.所以我在这里犯了一些错误吗?谢谢.
我有 3 张桌子可以相互连接。表名称的角色、role_user 和用户。我想在 laravel 上进行迁移并添加一些约束。这是我的角色表迁移中的内容:
Schema::create('roles', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('description');
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
这是我的用户表迁移:
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('username')->unique();
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->boolean('active')->default(0);
$table->softDeletes();
$table->rememberToken();
$table->timestamps();
});
Run Code Online (Sandbox Code Playgroud)
这是我的 role_user 表迁移:
Schema::create('role_user', function (Blueprint $table) {
$table->integer('role_id')->unsigned();
$table->integer('user_id')->unsigned();
$table->unique(['role_id', 'user_id']);
$table->foreign('role_id')->references('id')->on('roles')
->onDelete('cascade')->onUpdate('cascade');
$table->foreign('user_id')->references('id')->on('users')
->onDelete('cascade')->onUpdate('cascade');
});
Run Code Online (Sandbox Code Playgroud)
在我的迁移顺序中,我已经将角色表放在用户之上,但是我遇到了这种错误:
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `role_user` add constraint `role_user_role_id_foreign` foreign key (`role_id
`) references `roles` (`id`) on delete cascade on update cascade) …Run Code Online (Sandbox Code Playgroud) 我将通知保存到数据库中,如下所示:
public function toDatabase($notifiable)
{
return [
'from' => $this->message->name,
'name'=> $this->message->email,
'subject' => $this->message->subject,
'body' => $this->message->body
];
}
Run Code Online (Sandbox Code Playgroud)
它工作正常。现在我想将这些数据提取到我的视图中,所以我这样做:
@foreach ( Auth::user()->unreadNotifications as $notification)
<li><!-- start message -->
<a href="#">
<!-- Message title and timestamp -->
<h4>
{{ $notification->name }}
<small><i class="fa fa-clock-o"></i> 5 mins</small>
</h4>
<!-- The message -->
<p>{{ $notification->subject }}</p>
</a>
</li>
@endforeach
Run Code Online (Sandbox Code Playgroud)
但它什么也没给我。所以我做错了吗?
我有 2 个表:具有列(id、用户名、密码)的用户和具有列(user_id、失败、时间)的 user_failed。有什么可能的方法可以仅使用用户名插入表 user_failed 中?我尝试这段代码但失败了:
INSERT INTO `login_attempts`(`user_id`, `time`, `failed`)
VALUES (SELECT user_id FROM users WHERE username = 'pokemon','',3)
Run Code Online (Sandbox Code Playgroud) 我是symfony的新手,在按照说明安装后,它说我必须运行:
bin/console server:run
Run Code Online (Sandbox Code Playgroud)
我在我的symfony instalation文件夹中输入它.但是我得到了错误:
Could not open input file: bin/console
Run Code Online (Sandbox Code Playgroud)
然后我在这里搜索答案,它告诉我运行app/console
bin/console server:run
Run Code Online (Sandbox Code Playgroud)
但它只是遇到了同样的问题.是我想念一些bin文件夹这里还是什么?因为我无法在项目根文件夹中看到bin文件夹或app文件夹.这是我的项目文件夹结构:

我有一个像这样的 jquery 代码:
let $options = JSON.parse(data.options);
let $keys = Object.keys($options);
$keys.forEach(function (item,index, array) {
$('#' + item ).val($options[item] );
});
Run Code Online (Sandbox Code Playgroud)
我想用 $options 中的数据填充 $keys 中 id 中的所有输入值。但它不起作用。但是如果我像这样手动执行它,它会起作用:
$("#title").val($options.title);
$("#type").val($options.type);
$("#location").val($options.location);
Run Code Online (Sandbox Code Playgroud)
我确定问题出在这段代码中: $('#' + item )我尝试了很多东西,但似乎不起作用。那么有什么办法可以解决这个问题吗?
这是我的 HTML:
<div class="modal fade" id="widget_modal" tabindex="-1" role="dialog" aria-labelledby="AddUserModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<form id="widget_form" class="form-horizontal" method="post" enctype="multipart/form-data" action="/admin/widgets/store">
<input type="hidden" id="csrf" name="csrf_token">
<input type="hidden" name="id" id="id">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">
Add Widget
</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span …Run Code Online (Sandbox Code Playgroud) 我正在使用 Jquery 验证插件,一切正常,但是当我尝试验证复选框时出现错误:
TypeError: b is undefined
Run Code Online (Sandbox Code Playgroud)
这是我的引导复选框脚本:
<div class="col-xs-8">
<div class="checkbox icheck">
<label>
<input type="checkbox" required> I agree to the <a href="#">terms</a>
</label>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
这是我使用的 jquery 验证:
$("#formRegister").validate({
errorElement: "span",
errorClass: "help-block",
highlight: function (element, errorClass, validClass) {
// Only validation controls
if (!$(element).hasClass('novalidation')) {
$(element).closest('.form-group').removeClass('has-success').addClass('has-error');
}
},
unhighlight: function (element, errorClass, validClass) {
// Only validation controls
if (!$(element).hasClass('novalidation')) {
$(element).closest('.form-group').removeClass('has-error').addClass('has-success');
}
},
errorPlacement: function (error, element) {
if (element.parent('.input-group').length) {
error.insertAfter(element.parent());
}
else if (element.prop('type') === …Run Code Online (Sandbox Code Playgroud) laravel ×3
laravel-5 ×3
jquery ×2
php ×2
javascript ×1
json ×1
migration ×1
mysql ×1
sql ×1
sql-insert ×1
symfony ×1
validation ×1