我收到这个奇怪的错误:
SQLSTATE [42S22]:未找到列:1054'字段列表'中的未知列'0'(SQL:update
forum_threads
set0
= locked,1
= 1,updated_at
= 2016-03-17 16:01:59其中topic_id
= 3和forum_threads
.deleted_at
为null)
问题是,我没有0列.0
我的代码中没有where子句.我正在使用范围查询.
我的控制器是:
$action = $request->input('action');
$topic = $request->input('topic');
$thread = Thread::where('topic_id', $topic);
switch ($action) {
case ('locked'):
$thread->lock();
break;
}
Run Code Online (Sandbox Code Playgroud)
如你所见,我做得不多.我只是想锁定一个线程.我在我的Thread
模型中调用锁定范围.我有很多开关盒,其中一个是lock
.我在顶部运行了一半的查询,所以我不必重复自己.我只是将它存储在$thread
变量中,以便我可以执行$thread->delete()
和的操作$thread->restore()
.
我在Thread模型中的查询范围:
public function scopeLock($query)
{
return $query->where('locked', 0)->update(['locked', 1]);
}
Run Code Online (Sandbox Code Playgroud)
而已.我想这可能是因为我有一个where子句从我的controller(Thread::where('topic_id', $topic)
)传递而且我只是继续它到我的范围.
任何帮助都非常感谢.
当我上传文件时,我将它们上传到共享主机中.问题是我的codeigniter的文件和文件夹位于其中一个网站名称文件夹中.
当我访问该网站时,它给我一个404错误.
我的.htaccesss
档案:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications …
Run Code Online (Sandbox Code Playgroud) 我在创建新帐户时遇到此错误.
(1/2)ClientException客户端错误:
POST https://api.coinbase.com/v2/accounts
导致400 Bad Request
响应:{"errors":[{"id":"invalid_request","message":"不支持创建多个BTC帐户"}}}(2/2)InvalidRequestException不支持创建多个BTC帐户
这是新的吗?我过去创建了多个BTC帐户,但它不再起作用了.有没有解决这个问题.
顺便说一下,我指的是https://developers.coinbase.com/api/v2#create-account
谢谢.
我有一个加载并生成7个不同随机数的表单,从1到13,1是Ace,13是King.在生成7个不同的随机数后,它将每个随机数放入7个图像框中.我正在使用if语句显示图片框.
它还循环通过一系列"黑桃,心,俱乐部和钻石",13次.
我的if语句如下:
if (cardNum == 1 && cardType == "Spades")
{
pictureBox1.Image = ace_of_spades;
}
else if (cardNum == 1 && cardType == "Hearts")
{
pictureBox1.Image = ace_of_hearts;
}
else if (...)
{
//change picture box
} //repeat it like 50 times
Run Code Online (Sandbox Code Playgroud)
是否有一种简单,容易的方法来挑选7张随机卡并在图片框中显示它们?
这是非常耗时的,就像我这样做.
我有一个小问题。有两种用户角色,一种是普通成员,一种是管理员。成员可以删除博客,并且在删除(软删除)博客后他们将无法看到该博客,而管理员仍然可以看到该博客,即使它是软删除的。
示例代码:
// Route file
Route::get('/blog/{blog}', 'BlogController@show');
// BlogController
public function show(App\Blog $blog) {
// It never gets to here if the blog has been soft deleted...
// Automatically throws an 404 exception
}
Run Code Online (Sandbox Code Playgroud)
我希望管理员能够访问博客,即使它被软删除,但它实际上不起作用。我正在尝试编辑路线服务提供商,但我没有得到任何运气,因为它不允许我使用该Auth::user()
功能来获取登录用户,以便我可以检查他们是否有权限。
我的RouteServiceProvider
$router->bind('post', function($post) {
if (Auth::user()->isAdmin()
return Post::withTrashed()->where('id', $post)->firstOrFail();
});
Run Code Online (Sandbox Code Playgroud)
这不起作用,因为它不知道Auth::user()
是什么。我已经导入了Auth
门面,但仍然不起作用。
编辑:null
当我转储和死亡时,它给了我一个价值Auth::user()
。
非常感谢任何帮助。
我正在执行ajax请求,如果验证失败,则会向用户显示错误消息.
但是,用户还可以在控制台中看到错误消息.例如,如果用户未在控制台中完成其中一个字段,则显示以下内容:
无法加载资源:服务器响应状态为422(不可处理的实体)
我不希望他们看到错误.如何防止他们看到这样的错误以及控制台中的其他错误,如501错误和内容.我只是想显示一条警告"发生错误".我不想在控制台中显示任何内容.
我目前的AJAX代码:
(function ($) {
$('#settingsForm').submit(function (e) {
$.ajax({
type: "POST",
dataType: 'JSON',
url: '/settings',
data: $('#settingsForm').serialize(),
beforeSend: function () {
},
success: function (data) {
message(data);
},
error: function (data) {
if (data.status === 422 ) {
var errors = $.parseJSON(data.responseText);
errorsHtml = '<div class="alert alert-danger"><ul>';
$.each(errors, function (index, value) {
errorsHtml += '<li>' + value + '</li>';
});
errorsHtml += '</ul></div>'
$('#status_settings').html(errorsHtml);
}
}
})
;
e.preventDefault();
})
;
})
(window.jQuery);
Run Code Online (Sandbox Code Playgroud) 我在7年级,我正在为我们班级建立一个网站.我正在尝试使用一些论坛,在我的xampp数据库中,这是在"配方"下.这是什么类型的代码?
a:1:{s:2:"to";a:2:{i:0;s:1:"1";i:1;s:1:"2";}}
Run Code Online (Sandbox Code Playgroud)
谢谢.
我处于这样一种情况,我有很多关系,并且当我进行大量查询时,它会减慢网站速度,这正成为一个问题。
例如,我正在为所有博客执行 foreach 循环并获取创建博客的用户。
@foreach ($blogs as $blog)
<a href="{{ route('blog.view', str_slug($blog->title)) }}">{{ $blog->title }}</a>
{{ $blog->created_at }}
<a href="{{ viewProfile($blog->user) }}"><{{ $blog->user->username }}/a>
Last Commenter:
<a href="{{ viewProfile($blog->lastCommenter()->user) }}">
{{ $blog->lastCommenter()->user->username }}
</a>
@endforeach
Run Code Online (Sandbox Code Playgroud)
仅此一项就超过 50 多个查询。如果有 100 个博客,查询的数量就远远不够了。
我怎样才能避免这样做?我已将它存储在此视图中的一个变量中,但我不想真正将任何 PHP 代码放入刀片文件中。我怎样才能避免这样做?我曾尝试在数据库中使用缓存,但这也对数据库中的缓存表进行了一些查询。我也在使用急切加载,这有很大帮助。但是我怎样才能最好地做这种事情呢?
非常感谢您提前回复。
有一个名为“faq”的语言文件,其中列出了所有常见问题和答案。
我不知道如何从这些语言文件中执行 foreach 循环。
我的 faq.php 语言文件:
return [
'faq_1' => 'Question here',
'faq_1_ans' => 'Answer here',
'faq_2' => 'Question here',
'faq_2_ans' => 'Answer here',
];
Run Code Online (Sandbox Code Playgroud)
我怎样才能把它变成一个 foreach 循环?我真的不知道从哪里开始。
我刚刚遇到了这个奇怪的问题.我正在将我的代码部署到测试服务器,一切都是一样的.
我有一个简单的 $laptop = Laptops::where('name', 'Mac')->first() ?: new BlankLaptop();
该BlankLaptop
班是一个扩展的空类Laptops
类.
然后我做
if ($laptop->exists()) // do something
Run Code Online (Sandbox Code Playgroud)
问题是它总是在生产中返回true,即使在I时dd($laptop)
,生产和本地服务器的结果都是相同的.
但是,当我这样做$laptop->exists
(没有括号)时,它确实返回正确的值.
有没有之间的不同->exists()
和->exists
?
谢谢.
php ×9
laravel ×7
laravel-5 ×3
.htaccess ×1
ajax ×1
c# ×1
caching ×1
codeigniter ×1
coinbase-api ×1
coinbase-php ×1
if-statement ×1
jquery ×1
json ×1
mysql ×1
routes ×1