此代码的工作原理是inn_db
从 发送到表ext_db
。
但它无法检查 中的数据是否相同或不同inn_db
。
所以在 中提出了相同的值inn_db
。
我怎样才能添加那个工作?
Laravel-5.4、MySQL、InnoDB。
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use \DB;
class UpdateCustomerController extends Controller
{
public function db_update()
{
$customers = \DB::connection('ext_db')->table('customers')->orderBy('customer_id')->chunk(1000, function ($all){
foreach ($all as $kunde){
DB::connection('inn_db')->table('custoemrs')->insert(
[$kunde->customer_id
$kunde->name,
$kunde->email]);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
最后,经过讨论,我得到了如下代码和连接视图的答案。
感谢@Pramid 和@Badea :)
$customers = \DB::connection('ext_db')->table('customers')->orderBy('customer_id')->chunk(1000, function ($all){
foreach ($all as $kunde){
$existing_kunde = DB::connection('inn_db')->table('customers')->where([
['customer_id', '=', $kunde->customer_id],
['name', '=', $kunde->name],
['email', '=', $kunde->email]
])->first();
if ( ! $existing_kunde) …
Run Code Online (Sandbox Code Playgroud) 如果模型事实如下所示,那么如何在其中使用Trait getData()?
此代码无效。
<?php
use App\Working;
use App\Traits\Calculate;
...
$factory->define(App\Working::class, function (Faker\Generator $faker) {
...
$getData = $this->getData();
...
return['get_data' => $getData];
}
Run Code Online (Sandbox Code Playgroud)
错误信息:
Symfony \ Component \ Debug \ Exception \ FatalThrowableError:调用未定义的方法Illuminate \ Database \ Eloquent \ Factory :: getData()
异常跟踪:
1 Illuminate \ Database \ Eloquent \ Factory :: {closure}(Object(Faker \ Generator),[])G:\ test \ vendor \ laravel \ framework \ src \ Illuminate \ Database \ Eloquent \ FactoryBuilder.php:263
2 call_user_func(Object(Closure),Object(Faker \ Generator),[])G:\ test \ vendor \ laravel …
I wish to make search query by datepicker and select field. How could I get the requests values from below view file to controller? Where could I modify in the code? thanks.
index.blade.php
<div class="form-group col-sm-6">
{!! Form::open(array('class' => 'form', 'method' => 'get', 'url' => url('/pdfs/job_finished_search'))) !!}
{!! Form::input('text', 'datepicker_from', null, ['placeholder' => 'Fra', 'id' => 'datepicker_from']) !!}
{!! Form::input('text', 'datepicker_to', null, ['placeholder' => 'Til', 'id' => 'datepicker_to']) !!}
{!! Form::select('customer_name', $jobs->pluck('customer_name', 'customer_name')->all(), null, ['class' => 'form-control']) !!}
{!! Form::submit('Søke', …
Run Code Online (Sandbox Code Playgroud) laravel laravel-request laravel-response laravel-query-builder