我有以下SQL查询:
SELECT * from db.tableA WHERE field in (SELECT id FROM db.tableB where other_field = value);
我希望select from field where tableA在由子查询返回的值数组中。问题是:我怎样才能用eloquent做到这一点?我目前的解决方案(我认为非常丑陋)如下:
$a = \App\tableB::where("other_field", "=", $value)->select('id')->get();
$
我将通过查询读取数据,操作一些值并将其写回数据库。我使用下面的代码,但是我得到了一个错误。
$data = DB::table('users')->get()->toArray();
foreach ($data as $d){
$d->id = $id+100;
DB::table('users')->insert($d);
}
Argument 1 passed to Illuminate\Database\Query\Builder::insert() must be of the type array,
但是输入已经是一
我有一个数组,它是由几个sql请求产生的。首先,我在foreach中提出了一个sql请求,以便拥有我需要的所有数据。
foreach ($users as $user) {
// Two different Eloquent requests
$todo = User::select().....where('users.id' = $id);
$done = User::select().....where('users.id' = $id);
// I have operation on Collection that work
嗨,我有很多充满口才的查询,在我的应用程序的前奏循环,我试图避免这种做法在可能的地方。
示例:
$statuses = Statuses::get(); // or Statuses::all(); // What's the difference because I use them mixed?
$statusList = [];
foreach ($statuses as $status) {
$statusList[$status->id] = $status->status_title;
} // How do I just get my array
json:
[
{"student":"a","relation":"son","id":"74"},
{"student":"b","relation":"son","id":"75"}
]
我想要得到这个json中每个id的值(例如74和75)。这个json来自一个名为relation from user table的列。
我正在和laravel一起工作。
我试图使用laravel的有用的种子函数来填充具有自定义数据的表。我没有使用Faker,而是使用Seeder。因此,我创建了一个:
‘/ JSON /’文件夹并将我的JSON数据文件放在那里。
最后,在种子器中,我将数据映射到JSON对象属性。
这是我的密码。
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
class JsonTableSeeder extends Seeder
{
/**
我在使用laravel maatwebsite excel,
我尝试传递变量并执行一些操作并作为数组返回以进行导出,
因此,当我试图将数组传递给用于excel导出的主控制器时,我会得到错误(下载)。
我的主控制器
public function excel_export(Request $request){
return Excel::download(new UsersExport($request->exp_vlas), 'users.xlsx');
}
这里,iam将变量传递给集合
我的出口控制器
public function collection(){
我有三个函数,它是a() b()和c()
然后,函数a()返回:
{
id =>
total1 =>
}
函数b()也像funcion ()一样返回,但是有一个不同的值(total1和total2)
函数c()返回:
{
id => //same value just like function a or b
name =>
}
$a = $model->a(); // from function a();
$b = $model->b(); // from function b();
$c = $model->
我正在实施拉拉通知。通知存储在通知表中。我试图获取数据列中的数据并在刀片中显示,但失败了。
这是我的控制器
public function notification_list(){
$notifications = auth()->user()->notifications()->orderBy('created_at','desc')->get();
return view('users.notification.index')->with('notifications',$not