我创建了一个非常简单的查询,但是laravel添加了额外的查询,我想删除它。
\DB::enableQueryLog();
App\Proj::whereNotNull('deleted_at')->paginate(20);
dd(\DB::getQueryLog());
其中提出的查询如下:
select * from `projs` where `deleted_at` is not null and `projs`.`deleted_at` is null
要获得好的结果,所需的查询如下:
select * from `projs` where `delete
基本上我设法让我的软删除在我的用户表上工作,问题是现在我的其他页面将不能工作,我相信我需要使用withTrashed对页面的查询进行一些更改?例如下面所示的控制器,我如何添加已经被软删除的用户列,有人可以指导我和帮助我吗?
Controller.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Zone;
use App\Parameter;
class
我想通过Laravel的查询构建器开始使用软删除模型
顺便说一下,我创建了列deleted_at,并在模型中实现了软删除模型。
Request.php:
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request as Req;
use Illuminate\Database\Eloquent\SoftDeletes;
class Request extends Model
{
use SoftDeletes;
}
RequestController函数:
public fun
我是个初学者,找不到解决我的问题的办法。我试图从我的数据库中获取"onlyTrashed“,但是Laravel 8不接受我的查询命令:(我尝试了很多场景,但都没有成功。 namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use App\Models\Category;
class CategoryController extends Controller{
pu
在使用Laravel创建了几个应用程序并使用了softDelete属性之后,我意识到,在几个控制器中,像destroy()、restore()和kill()这样的方法是完全相同的。因此,我试图把它们放在一个特性中,并从不同的控制器中使用它。
我的代码如下:
ProfilesController.php
<?php
namespace App\Http\Controllers;
use App\Profile;
class ProfilesController extends Controller
{
public function destroy(Profile $prof
我遇到了奇怪的问题,我想从我的模型中获取数据,但我不能这样做,我的其他模型工作得很好,但其中一个模型在表有数据的情况下返回空数组,这是我的模型: <?php
namespace App\Hotels;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Hotel extends Model
{
use SoftDeletes;
protected $table = 'hotels';
protected $fill
下面的软删除代码对我来说很好用:
$post = Post::find($post_id);
$post->delete();
将更新deleted_at字段。但这给了我一个错误:
$post = Post::find($post_id);
$post->restore();
下面是错误:
exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to a member function restore() on a non-object'
我有两张桌子,
user
intern
一个user belongsTo一个实习生,一个intern hasOne用户。我的问题是,当我软删除一个user记录和相关的intern记录时。我想恢复它我再也找不到相关的实习生了。
所以当我像这样找到用户时:
$user = user::onlyTrashed()->find($userId);
然后说$user->intern结果为null,因为它找不到intern
Trying to get property of non-object
我该怎么解决这个问题呢?
我们正在运行Server 2008。在查看我在sys.dm_db_missing_index_*视图上运行的查询的结果时,我看到了一个关于包含列的奇怪建议。我有以下两张表:
create table foo (
id int not null identity(1,1) primary key
/* many more fields, not relevant to question */
)
create table bar (
id int not null identity(1,1) primary key
foo_id int not null,
我正在尝试构建一个非常简单的android应用程序,在接收到来自MainActivity类的值之后,使用数据库的MySQL查询在MySQL中显示一些数据。我已经在MySQL服务器上测试了这些查询,它们是正确的,但是当我在应用程序中运行它们时,它们都会完全返回一行,而实际上每次运行winScheduleQuery和lossScheduleQuery都应该返回0到10行左右的任何地方,这对于teamQuery结果的每一行都是如此。所以有些奇怪的事情发生了,但我搞不懂。下面是运行查询的活动类.
public class ViewTeamsActivity extends Activity {
这是我使用的查询:
$q = $this->getEntityManager()->createQueryBuilder("SELECT e FROM ActionModule\Action e JOIN e.type t WHERE t.id IN (:ids)");
我尝试了每个参数赋值选项:
*身份证
?1
内爆( ',‘,$ids)
?身份证
并且总是得到:
原则\ORM\Query\QueryException
语法错误第0行-1:错误:预期的IdentificationVariable、ScalarExpression、