में गतिशील इनपुट डेटा सरणी को सहेज रहा है मैं लार्वेल में एक गतिशील रूप को सहेजने की कोशिश कर रहा हूं। डेटा बेस में डेटा सरणी को सहेजने में असमर्थ। निम्नलिखित रूप है। लार्वेल डेटाबेस
कम
{!! Form::select('customer_id', ['' => 'Select a customer'] + $customer_list ,null , array('class' => 'form-control', 'id' => 'customer')) !!}
{!! Form::text('mileage_in', null, ['class' => 'form-control', 'placeholder' => 'Mileage In']) !!}
.
.
.etc...
गतिशील प्रपत्र फ़ील्ड्स
{!! Form::select('item_id[][item_id]', $items, null, array('class' => 'form-control')) !!}
{!! Form::text('item_description[][item_description]', null, ['class' => 'form-control', 'placeholder' => 'Not Required | Optional']) !!}
{!! Form::text('units[][units]', null, ['class' => 'form-control', 'placeholder' => 'Add Units']) !!}
{!! Form::text('rate[][rate]', null, ['class' => 'form-control', 'placeholder' => 'Add Rate']) !!}
{!! Form::text('amount[][amount]', null, ['class' => 'form-control', 'placeholder' => 'Add Hrs and Rate', 'id' => 'amount']) !!}
उन सभी क्षेत्रों में सामान्य प्रपत्र फ़ील्ड्स उसी रूप में कर रहे हैं। मैं इन आंकड़ों को तीन अलग-अलग तालिकाओं में सहेज रहा हूं।
निम्नलिखित मॉडल हैं जिन्हें मैंने बनाया है।
अनुमान तालिका के लिए अनुमान मॉडल
class Estimate extends Model
{
protected $fillable = [
'customer_id',
'vehicle_id',
'mileage_in',
'net_amount',
'parent_estimate_id',
'department',
'created_by'
];
public function customer(){
return $this->belongsTo('App\Customer');
}
public function vehicle(){
return $this->belongsTo('App\Vehicle');
}
public function estimate_details(){
return $this->hasMany('App\EstimateDetail');
}
}
estimate_details तालिका के लिए EstimateDetail मॉडल आइटम तालिका के लिए
class EstimateDetail extends Model
{
protected $fillable = [
'estimate_id',
'item_id',
'item_description',
'units',
'rate',
'labor_amount_final',
'initial_amount',
'task_status'
];
public function item()
{
return $this->hasMany('App\Item');
}
public function estimate()
{
return $this->belongsTo('App\Estimate');
}
}
आइटम मॉडल
class Item extends Model
{
protected $fillable = [
'name',
'type',
'location',
'quantity',
'sale_price',
'unit_of_sale',
'pre_order_level',
'created_by',
'category_id',
'service_only_cost',
'updated_at'
];
public function estimate_details()
{
return $this->hasMany('App\EstimateDetail');
}
}
Foll कारण कोड EstimatesController
class EstimatesController extends Controller
{
public function store(EstimateRequest $request)
{
$user_id = '1';
$input = $request->all();
$vehicle = new Vehicle();
$vehicle->customer_id = $input['customer_id'];
$vehicle->reg_no = $input['reg_no'];
$vehicle->make = $input['make'];
$vehicle->model = $input['model'];
$vehicle->created_by = $user_id;
$estimate = new Estimate();
$estimate->customer_id = $input['customer_id'];
$estimate->vehicle_id = $input['vehicle_id'];
$estimate->mileage_in = $input['mileage_in'];
$estimate->department = $input['department'];
$estimate->created_by = $user_id;
$estimate_detail = new EstimateDetail();
$estimate_detail->item_id = $input['item_id'];
$estimate_detail->item_description = $input['item_description'];
$estimate_detail->units = $input['units'];
$estimate_detail->rate = $input['rate'];
$estimate_detail->initial_amount = $input['amount'];
$vehicle->save($request->all());
$vehicle->estimate()->save($estimate);
$estimate->estimate_details()->save($estimate_detail);
}
return redirect('/estimates');
}
मैं सफलतापूर्वक टेबल वाहनों और अनुमानों पर वाहन और अनुमान डेटा को बचा सकता है है। लेकिन मैं estimate_details तालिका पर अनुमान विवरण सरणी को सहेजने में असमर्थ हूं। कई अलग-अलग तरीकों की कोशिश की लेकिन आखिर में असफल रहा। कृपया मदद करें !!!
आपके उत्तर के लिए धन्यवाद। मैंने पहले यह कोशिश की। लेकिन मुझे यह त्रुटि मिल रही है। "preg_replace(): पैरामीटर मिस्चैच, पैटर्न एक स्ट्रिंग है जबकि प्रतिस्थापन एक सरणी है" – Dhananjaya
हां इसके कारण आप एक बार में सरणी डालने की कोशिश कर रहे हैं। $ estimate_detail-> item_id = $ इनपुट ['item_id'] [0] जैसी वस्तुओं के बाद एक अनुक्रमणिका जोड़ें; $ estimate_detail-> item_description = $ इनपुट ['item_description'] [0]; $ estimate_detail-> इकाइयों = $ इनपुट ['इकाइयों'] [0]; $ estimate_detail-> दर = $ इनपुट ['दर'] [0]; $ estimate_detail-> प्रारंभिक_माउंट = $ इनपुट ['राशि'] [0]; यदि यह काम करता है तो एक लूप के लिए जाएं। –
मैंने लूप के बिना इंडेक्स जोड़ने की कोशिश की। अभी भी एक ही त्रुटि हो रही है। "preg_replace(): पैरामीटर मिस्चैच ..." और 'estimate_details' ('estimate_id',' item_id', 'item_description',' इकाइयों', 'दर', 'प्रारंभिक_माउंट',' update_at' में डालने के रूप में विस्तृत त्रुटि के रूप में विस्तृत त्रुटि ', 'create_at') मान (89,?,?,?,?,?,?,?)" – Dhananjaya