ผมเกิดปัญหา ดึกข้อมูล จาก product 10000+ record แล้ว error 500 ครับ
Code (PHP)
$vendor = Vendor_profile::find($id)
dd($vendor)
Code (PHP)
Model Vendor Profile
class Vendor_profile extends Model
{
protected $table = 'vendor';
protected $primaryKey = 'vid';
public $timestamps = false;
protected $with = ['Product'];
public function Product(){
return $this->hasMany(Product::class,'vendId');
}
}
Model Product
class Product extends Model
}
protected $table = 'product';
protected $primaryKey = 'prId';
public $timestamps = false;
protected $with = ['Product_many_optional','Pjt_product_status'];
public function Vendor_profile(){
return $this->belongsTo(Vendor_profile::class,'vid');
}
database อะไร
spec แค่ไหน
ทำ index ไว้มั้ย
จำเป็นต้องเอามทั้งหมด 10,000 มั้ย ถ้าจำเป็น แล้ว server ไม่ไหว ทำ micro service วิ่ง get มาเก็บใน temp table ได้หรือเปล่า
มันมีหลายสาเหตุครับ
Date :
2018-12-07 17:39:13
By :
mongkon.k
No. 2
Guest
จงดูข้า
Province.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Province extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'provinces';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name'
];
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['created_at', 'updated_at'];
/**
* Get the districts for the province.
*/
public function districts() {
return $this->hasMany(District::class);
}
}
District.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class District extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'districts';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name'
];
/**
* The attributes that should be mutated to dates.
*
* @var array
*/
protected $dates = ['created_at', 'updated_at'];
/**
* Get the province of the district.
*/
public function province() {
return $this->belongsTo(Province::class);
}
CreateProvincesTable
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateProvincesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('provinces', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('provinces');
}
}
CreateDistrictsTable
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateDistrictsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('districts', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->timestamps();
});
Schema::table('districts', function (Blueprint $table) {
$table->integer('province_id')->unsigned()->after('name');
$table->foreign('province_id')->references('id')
->on('provinces')->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('districts', function (Blueprint $table) {
$table->dropForeign('districts_province_id_foreign');
});
Schema::drop('districts');
}
}