मेरे पास दो समान क्षेत्र थे, जैसे कि कुल_वेट जो कि मेरी फाइटो टेबल में है और वजन जो मेरी फाइटो_स्पेशीज़ तालिका में है जो नीचे दिखाया गया है
क्रिएटफाइटोसटेबल
public function up()
{
Schema::create('phytos', function (Blueprint $table) {
$table->id();
$table->string('customer_name');
$table->string('phyto_number');
$table->decimal('total_weight');
$table->date('date_send');
$table->softdeletes();
$table->timestamps();
});
}
CreatePhytoSpeciesTable
public function up()
{
Schema::create('phyto_species', function (Blueprint $table) {
$table->id();
$table->integer('phyto_id')->unsigned();
$table->integer('species_id')->unsigned();
$table->integer('destination_id')->unsigned();
$table->integer('preservation_id')->unsigned();
$table->double('weight', 8,2);
$table->softdeletes();
$table->timestamps();
});
}
मैं कुल वजन के रूप में array_sum() का उपयोग करके वजन का योग करने की कोशिश कर रहा हूं और फिर इसे नीचे दिखाए गए 'total_weight' => $totalweight] पर असाइन करता हूं, हालांकि जब मैं त्रुटि सहेजता हूं तो अपरिभाषित चर कहता है: कुल वजन। मैं कृपया सहायता के लिए अनुरोध करना चाहता हूं
public function store(CreatePhytoRequest $request)
{
$phyto = $this->phytoRepository->create(
['customer_name' => $request->customer_name,
'phyto_number' => $request->phyto_number,
'date_send' => $request->date_send,
'total_weight' => $totalweight]
);
$species = $request->input('species_id', []);
$weight = $request->input('weight', []);
$destination = $request->input('destination_id', []);
$preservation = $request->input('preservation_id', []);
for ($i=0; $i < count($species); $i++) {
if ($species[$i] != '') {
$phyto->species()->attach($species[$i], ['weight' => $weight[$i],'destination_id' => $destination[$i],'preservation_id' => $preservation[$i]]);
}
}
//array_sum work fine
$totalweight = array_sum($weight);
Flash::success('Phyto saved successfully.');
return redirect(route('consignment.phytos.index'));
}
1 उत्तर
चर घोषित करें
$totalweight = array_sum($weight);
इससे पहले कि आप इसे कॉल करें। आपका कोड कुछ ऐसा होना चाहिए:
public function store(CreatePhytoRequest $request) {
//Get everything from requests
$weight = $request->input('weight', []);
...
// Declare needed variables
$totalweight = array_sum($weight);
$phyto = $this->phytoRepository->create(
['customer_name' => $request->customer_name,
'phyto_number' => $request->phyto_number,
'date_send' => $request->date_send,
'total_weight' => $totalweight]);
... // and so one
}
संबंधित सवाल
नए सवाल
sql
संरचित क्वेरी भाषा (एसक्यूएल) डेटाबेस को क्वेरी करने के लिए एक भाषा है। प्रश्नों में कोड उदाहरण, तालिका संरचना, नमूना डेटा और DBMS कार्यान्वयन के लिए एक टैग (जैसे MySQL, PostgreSQL, Oracle, MS SQL Server, IBM DB2, आदि) का उपयोग किया जाना चाहिए। यदि आपका प्रश्न केवल एक विशिष्ट DBMS (विशिष्ट एक्सटेंशन / सुविधाओं का उपयोग करता है) से संबंधित है, तो इसके बजाय उस DBMS के टैग का उपयोग करें। एसक्यूएल के साथ टैग किए गए सवालों के जवाब में आईएसओ / आईईसी मानक एसक्यूएल का उपयोग करना चाहिए।