How to fix
Call to a member function row() on null
THIS IS MY CONTROLLER
function forwardtrack($param='',$param2='') {
if(sizeof($this->db->get_where('st_forward',array('letter_no' =>$param.'/'.$param2))->result_array())>0 && (!($param.'/'.$param2) )){
$data1['message']= 'notallow';
$this->load->view('track1',$data1);
}
else{
$data1['name']=$this->db->get_where('bpas_user_profiles',array('AgencyMainParentID' =>$this->session->userdata('ministryId'),'AgencyParentID'=>$this->session->userdata('parentID'),'AgencyID'=>$this->session->userdata('agencyID')))->result_array();
$data1['userdeatils']=$this->ag->tracks($param.'/'.$param2);
$this->load->view('userManagement/forward2', $data1);
}
/* ag=> agency model */
}
THIS IS MY MODEL
public function tracks($letterno="")
{
$query= $this->db->get_where('st_dak_details',array('dakLetterNo'=>$letterno))->row();
return $query;
}
THIS VIEW PAGE
<br/>
<div class="container">
<div class="panel panel-info">
<div class="panel-heading">
<i class="fa fa-envelope-o fa-fw"></i>forward to
</div>
<div class="panel-body">
<form class="form-horizontal" enctype="multipart/form-data" action="#" method="post" id="forwardmessage">
<div class="form-group">
<label for="letter"class="col-xs-12 col-lg-1 col-sm-1 col-md-1">letter_no: </label>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<?php
foreach($userdeatils->row() as $row): ?>
<input name="dakLetterNo" id="dakLetterNo" value="<?php echo $row['dakLetterNo'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<!-- <div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">created: </label>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="copy_to" id="copy_to" value="<?php //echo $userdeatils->created;?>"readonly="true" class="form-control" type="text" required />
</div> -->
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2 control-label">Attachment: </label>
<div class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<input type="file" name="Attachment" id="Attachment">
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Subject: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon" id="subjecterr"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="subject" id="Remark" value="<?php echo $row['Remark'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Place: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="place" id="place" value="<?php echo $row['place'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">from: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="from" id="receieve_add" value="<?php echo $row['receieve_add'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Created: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="created" id="created" value="<?php echo $row['created'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<!-- </div> -->
<!-- <div class="form-group"> -->
<!-- <label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Message: </label> -->
<!-- <div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10"> -->
<!-- <span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span> -->
<!-- <input name="message" id="message" value="<?php //echo $userdeatils->created;?>"readonly="true" class="form-control" type="text" required /> -->
<!-- </div> -->
<!-- </div> -->
<?php endforeach;?>
<div class="form-group">
<label class="col-lg-2 col-xs-12 col-sm-2 col-md-2">Message: </label>
<div class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<textarea class="form-control" id="message" name="message"></textarea>
<span id="messageerr" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 col-xs-12 col-sm-2 col-md-2">
Forward to
</label>
<div class="col-lg-6 col-xs-12 col-sm-6 col-md-6">
<select name="forwardto[]" id="agency" class="form-control">
<option value="">Select</option>
<?php
foreach($name as $row): ?>
<option value="<?php echo $row['cid']?>">
<?php echo $row['FirstName'].$row['MiddleName'].$row['LastName']?>
</option>
<?php endforeach;?>
</select>
<span id="forwarderr" class="text-danger"></span>
</div>
Model:
public function tracks($letterno="")
{
$query= $this->db->get_where('st_dak_details',array('dakLetterNo'=>$letterno));
if ($query->num_rows() > 0) {
return $query->row();
} else {
return array();
}
}
Controller:
function forwardtrack($param = '', $param2 = '') {
if (sizeof($this->db->get_where('st_forward', array('letter_no' => $param . '/' . $param2))->result_array()) > 0 && (!($param . '/' . $param2) )) {
$data1['message'] = 'notallow';
$this->load->view('track1', $data1);
} else {
$data1['name'] = $this->db->get_where('bpas_user_profiles', array('AgencyMainParentID' => $this->session->userdata('ministryId'), 'AgencyParentID' => $this->session->userdata('parentID'), 'AgencyID' => $this->session->userdata('agencyID')))->result_array();
$data1['userdeatils'] = $this->ag->tracks($param . '/' . $param2);
$this->load->view('userManagement/forward2', $data1);
}
/* ag=> agency model */
}
View:
<?php
if(!empty($userdeatils)){
foreach($userdeatils as $row) { ?>
//yout html code
...
...
<?php } ?>//foreach close
<?php } ?>//if close
Related
I want to insert buyer name from dropdown list into database. how can I select my dropdown selected text and save it into database table. I have a dropdown field and some text field to insert data into my database table.
Here is my controller:
function GetBuyerList(){
$buyerList=BuyerModel::all();//get data from table
// $buyerList=BuyerModel::lists('buyer_name','id');
//return $buyer_name;
return view('order',compact('buyerList'));//send data to view
}
function CreateOrder(Request $request){
$user_id= $request->input('user_id');
$buyer_name= $request->input('buyer_name');
$style_name= $request->input('style_name');
$season= $request->input('season');
$brand_name= $request->input('brand_name');
$garmments_type= $request->input('garmments_type');
$order_quantity= $request->input('order_quantity');
$fob= $request->input('fob');
$total_fob= $request->input('total_fob');
$merchandiser_name= $request->input('merchandiser_name');
$order_no= $request->input('order_no');
$order_date= $request->input('order_date');
$status= $request->input('status');
$input_date= $request->input('input_date');
$note= $request->input('note');
$result=OrderModel::insert([
'user_id'=>$user_id,
'buyer_name'=>$buyer_name,
'style_name'=>$style_name,
'season'=>$season,
'brand_name'=>$brand_name,
'garmments_type'=>$garmments_type,
'order_quantity'=>$order_quantity,
'fob'=>$fob,
'total_fob'=>$total_fob,
'merchandiser_name'=>$merchandiser_name,
'order_no'=>$order_no,
'order_date'=>$order_date,
'status'=>$status,
'input_date'=>$input_date,
'note'=>$note,
]);
return view('order');
}
Here is my blade code
#extends('Layout.app')
#section('content')
<br><br><br><br>
<div class="orderDiv container col-8">
<div class="d-flex justify-content-center align-items-center my-10 ">
<div class="card full-width">
<div class="card-header">
<h3>Orders</h3>
</div>
<div class="card-body">
<form>
<div class="row">
<div class="col-md-2">
<label for="category" class=" control-label">Buyer Name</label>
</div>
<div class="col-md-4">
<select class="buyerselect form-control full-width" id="buyerSelectId" name="buyer" required="">
<option value="0" disabled="true" selected="true">-Select Buyer-</option>
#foreach($buyerList as $buyer)
<option value="{{$buyer->id}}">{{$buyer->buyer_name}}</option>
#endforeach
{{-- <option selected value="">Select Buyer</option>--}}
{{-- <option value='564'>564</option>--}}
</select>
{{-- {!! Form::select('id',$buyerList,null,['class'=>'form-control']) !!}--}}
</div>
<div class="col-md-4">
<button id="buyerModalBtnId" type="button" class="btn btn-primary" data-mdb-toggle="modal" data-mdb-target="#addBuyerModal"><i class="fas fa-plus"></i>
Add New Buyer
</button>
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Style#</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Season</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Brand</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row">
<div class="col-md-2">
<label for="category" class=" control-label">Garments Type</label>
</div>
<div class="col-md-4">
<select class="form-control select2" name="garmentstype" style="width: 75%;" required="">
<option selected value="">Select Garments</option>
<option value='Baby Jacket'>Baby Jacket</option>
</select>
</div>
<div class="col-md-4">
<button type="button" class="btn btn-primary" data-mdb-toggle="modal" data-mdb-target="#exampleModal2"><i class="fas fa-plus"></i>
Add Germants Type
</button>
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Company Name</label>
</div>
<div class="col-md-4">
<select class="form-control full-width" name="buyer" required="">
<option selected value="">Select Company</option>
<option value='564'>Friend's Knittings</option>
<option value='Benetton'>Debonair Ltd</option>
<option value='HM'>Orbitex Knitting</option>
<option value='CA'>DPQSL</option>
</select>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Order Qty</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">FOB</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Concern Merchandiser</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-2">
<div class="col-md-2">
<label for="category" class=" control-label">orderDate</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">OrderNo</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-12">
<center>
<button type="submit" class="btn btn-success">Submit</button>
</center>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- modal 1 -->
<div class="modal fade" id="addBuyerModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Buyer</h5>
<button type="button" class="btn-close" data-mdb-dismiss="modal" aria-label="Close"></button>
</div>
<form>
<div class="modal-body">
<div id="addBuyerInformationId" class="form-group">
<label for="tstock" class="col-sm-2 control-label">Buyer Name</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="addBuyerNameId" name="garmentstype" placeholder="Input Buyer Name">
</div><br>
<label for="tstock" class="col-sm-2 control-label">Buyer Country</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="addBuyerCountryId" name="garmentstype" placeholder="Input Buyer Country">
</div>
<br>
</div><br>
<br>
<label for="tstock" class="col-sm-2 control-label">User Id</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="addBuyerUserId" name="garmentstype" placeholder="Input User Id">
</div>
<br>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-mdb-dismiss="modal">
Close
</button>
<button id="buyerAddConfirmButton" type="button" class="btn btn-primary" >Save changes</button>
</div>
<!-- modal2 -->
<div class="modal fade" id="exampleModal2" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Create Garments Type</h5>
<button type="button" class="btn-close" data-mdb-dismiss="modal" aria-label="Close"></button>
</div>
<form>
<div class="modal-body">
<div class="form-group">
<label for="tstock" class="col-sm-2 control-label">Select</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="garmentstype" name="garmentstype" placeholder="Garments Type">
</div>
<br>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-mdb-dismiss="modal">
Close
</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
<!-- End your project here-->
#endsection
I already insert data into buyer table
My custom.js file
$(document).ready(function () {
$('#VisitorDt').DataTable();
$('.dataTables_length').addClass('bs-select');
});
$('#buyerModalBtnId').click(function() {
$('#addBuyerModal').modal('show');
});
$('#buyerAddConfirmButton').click(function() {
// var id=$(this).data('id');
var name = $('#addBuyerNameId').val();
var country = $('#addBuyerCountryId').val();
var user=$('#addBuyerUserId').val();
BuyerAdd(name, country,user);
});
function BuyerAdd(buyerName, buyerCountry,buyerUserId) {
if (buyerName.length == 0) {
toastr.error('Buyer Name is Empty !');
} else if (buyerCountry.length == 0) {
toastr.error('Buyer Description is Empty !');
}
else if (buyerUserId.length == 0) {
toastr.error('Buyer User Id is Empty !');
}
else {
$('#buyerAddConfirmButton').html("<div class='spinner-border spinner-border-sm' role='status'></div>"); ///Animation Set
axios.post('/BuyerAdd', {
name: buyerName,
country: buyerCountry,
user_id:buyerUserId,
})
.then(function(response) {
$('#buyerAddConfirmButton').html("Add");
if (response.status == 200) {
if (response.data == 1) {
// alert('Success');
$('#addBuyerModal').modal('hide');
toastr.success('Add Successfull');
$('#buyerAddConfirmButton').addClass('data-mdb-dismiss');
//getServicesData();
} else {
// alert('Failed');
$('#addBuyerModal').modal('hide');
toastr.error('Add Failed !!');
//getServicesData();
}
} else {
$('#addBuyerModal').modal('hide');
toastr.error('Something Went Wrong');
}
})
.catch(function(error) {
$('#addBuyerModal').modal('hide');
toastr.error('Something Went Wrong');
});
}
}
// Order Data Part
Regardless of some formatting errors and codestyle, here is the short workflow for your question:
validate requested data
instead of insert, use OderModel::create($request->input())
make the fields in your Order Model fillable
if you still need to edit the request data, create a new array and then give it to the create method with (OrderModel::create($newModifiedRequestedData);)
Frontend/view is clear?
The request name which you are using in controller for buyer as buyer_name it should be same as select tag in name with buyer_name.
Replace you blade file with below code and check*
#extends('Layout.app')
#section('content')
<br><br><br><br>
<div class="orderDiv container col-8">
<div class="d-flex justify-content-center align-items-center my-10 ">
<div class="card full-width">
<div class="card-header">
<h3>Orders</h3>
</div>
<div class="card-body">
<form>
<div class="row">
<div class="col-md-2">
<label for="category" class=" control-label">Buyer Name</label>
</div>
<div class="col-md-4">
<select class="buyerselect form-control full-width" id="buyerSelectId" name="buyer_name" required="">
<option value="0" disabled="true" selected="true">-Select Buyer-</option>
#foreach($buyerList as $buyer)
<option value="{{$buyer->id}}">{{$buyer->buyer_name}}</option>
#endforeach
{{-- <option selected value="">Select Buyer</option>--}}
{{-- <option value='564'>564</option>--}}
</select>
{{-- {!! Form::select('id',$buyerList,null,['class'=>'form-control']) !!}--}}
</div>
<div class="col-md-4">
<button id="buyerModalBtnId" type="button" class="btn btn-primary" data-mdb-toggle="modal" data-mdb-target="#addBuyerModal"><i class="fas fa-plus"></i>
Add New Buyer
</button>
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Style#</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Season</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Brand</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row">
<div class="col-md-2">
<label for="category" class=" control-label">Garments Type</label>
</div>
<div class="col-md-4">
<select class="form-control select2" name="garmentstype" style="width: 75%;" required="">
<option selected value="">Select Garments</option>
<option value='Baby Jacket'>Baby Jacket</option>
</select>
</div>
<div class="col-md-4">
<button type="button" class="btn btn-primary" data-mdb-toggle="modal" data-mdb-target="#exampleModal2"><i class="fas fa-plus"></i>
Add Germants Type
</button>
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Company Name</label>
</div>
<div class="col-md-4">
<select class="form-control full-width" name="buyer" required="">
<option selected value="">Select Company</option>
<option value='564'>Friend's Knittings</option>
<option value='Benetton'>Debonair Ltd</option>
<option value='HM'>Orbitex Knitting</option>
<option value='CA'>DPQSL</option>
</select>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Order Qty</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">FOB</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">Concern Merchandiser</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-2">
<div class="col-md-2">
<label for="category" class=" control-label">orderDate</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-2">
<label for="category" class=" control-label">OrderNo</label>
</div>
<div class="col-md-8">
<input type="text" id="typeText" class="form-control" />
</div>
</div>
<div class="row py-3">
<div class="col-md-12">
<center>
<button type="submit" class="btn btn-success">Submit</button>
</center>
</div>
</div>
</div>
</form>
I have this problem and I have no idea why it's not working. I have tried so many code changes but I still get the same error when I try to submit a form. It's a simple form to insert data to tomany tables in db. All tables accept data with no error but payment_agrement table gives me this error:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (kassemschool.payment_agrements, CONSTRAINT payment_agrements_responisbleid_foreign FOREIGN KEY (responsible_id) REFERENCES payment_agrements (id)) (SQL: insert into payment_agrements (frais_inscription, payment_mois, Assurance, Garde, Transport, responsible_id, updated_at, created_at) values (450, 550, 400, 200, 300, 154, 2019-11-16 19:47:39, 2019-11-16 19:47:39))
This is my controller:
if(request()->has('rName')) {
$responsible = Responsible::create([
'ResponsibleName'=> $request->rName,
'ResponsibleCNI'=>$request->cni,
'responsible_number'=>$request->tele
]);
}
//Student::create($data);
if(request()->has('MontantP')) {
$payment=Payment::create([
'PaymentPaid'=>$request->MontantP,
'PaymentRemaining'=>$request->RestP,
'responsible_id'=>$responsible->id,
]);
}
if($request->hasFile('file')){
$student->images = $request->file->store('file');
}
if(request()->has('TransportR')) {
$transport=Transport::create([
'TransportPaid'=> $request->TransportP,
'TransportRemainning'=>$request->TransportR,
'TransportDateStart'=>$request->TdateStart,
'TransportDateEnd'=>$request->TdateEnd,
]);
}
if(request()->has('edateStart')) {
$payment_date = Payment_Date::create([
'PaymentDateStart'=>$request->edateStart,
'PaymentDateEnd'=>$request->edateEnd,
'payment_id'=>$payment->id,
]);
$letter = 'KassN';
$number =$request->env . 'G';
$number2 = $request->group;
$id='_'.rand();
$random = $letter.$number.$number2.$id;
if(request()->has('fName')) {
$student = Student::create([
'StudentFName'=> $request->fName,
'StudentLName'=> $request->lName,
'StudentDateStart'=>$request->edateStart,
'StudentDateEnd'=>$request->edateEnd,
'level_id'=> $request->env,
'group_id'=>$request->group,
'responsible_id'=> $responsible->id,
'payment_date_id'=>$payment_date->id,
'Payment_dure_id'=>$request->paymentD,
'payment_id'=>$payment->id,
'transport_id'=>$transport->id,
'student_code'=>$random
]);
}
if(request()->has('inscription')){
$agrement= Payment_agrement::create([
'frais_inscription'=>$request->inscription,
'payment_mois'=>$request->payment,
'Assurance'=>$request->assaurance,
'Garde'=>$request->garde,
'Transport'=>$request->fraiTransport,
'responsible_id'=>$responsible->id
]);
}
my create view
#extends('layouts.app')
#section('content')
#if (Route::has('login'))
#auth
#if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
back to <strong>Home</strong>
back to <strong>list</strong>
</div>
#endif
<div class="mr-auto offset-md-1" style="width: 200px;">
<input type="button" class="btn btn-danger btn-sm" name="" value="<- Reteur">
</div>
<div class="card-body">
<div class="container" style="width: 80%;">
<form action="{{url('student')}}" method="POST">
{{ csrf_field() }}
<div class="form-group">
<label for="firstName">First Name </label>
<input type="text" class="form-control" name="fName" id="elastName">
</div>
<div class="form-group">
<label for="lastName">Last name:</label>
<input type="text" class="form-control" name="lName" id="efirstName">
</div>
<div class="form-group">
<label for="responsable">Responsable Name:</label>
<input type="text" class="form-control" name="rName" id="responsable">
</div>
<div class="form-group">
<label for="cni">Responsable CNI:</label>
<input type="text" class="form-control" name="cni" id="cni">
</div>
<div class="form-group">
<label for="nuveau">Niveau:</label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="nuveau">Options</label>
</div>
<select class="custom-select" id="nuveau" name="env">
<option selected>Choose...</option>
#foreach($levels as $level)
<option value="{{$level->id}}">{{$level->LevelName}} </option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<fieldset>
<legend>Aggrement:<hr></legend>
<div class="form-group">
<label for="cni">Frais de inscription:</label>
<input type="text" class="form-control" name="inscription" id="cni">
</div>
<div class="form-group">
<label for="cni">paiement mensuel:</label>
<input type="text" class="form-control" name="payment" id="cni">
</div>
<div class="form-group">
<label for="cni">Frais de Assurance:</label>
<input type="text" class="form-control" name="assaurance" id="cni">
</div>
<div class="form-group">
<label for="cni">Frais de Garde:</label>
<input type="text" class="form-control" name="garde" id="cni">
</div>
<div class="form-group">
<label for="cni">Frais de transport:</label>
<input type="text" class="form-control" name="fraiTransport" id="cni">
</div>
</fieldset>
</div>
<div class="form-group">
<label for="nuveau">Group:</label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="group">Options</label>
</div>
<select class="custom-select" id="nuveau" name="group">
<option selected>Choose...</option>
#foreach($groups as $group)
<option value="{{$group->id}}">{{$group->group_name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="payment">Payment:</label>
<div class="input-group mb-3">
<div class="input-group-prepend">
<label class="input-group-text" for="payment">Options</label>
</div>
<select class="custom-select" id="payment" name="paymentD">
<option selected>Choose...</option>
#foreach($payment_dures as $payment_dure)
<option value="{{$payment_dure->id}}">{{$payment_dure->payment_dure_name}}</option>
#endforeach
</select>
</div>
</div>
<div class="form-group">
<label for="dateStart"></label>
<input type="date" class="#" id="dateStart" style="width: 49%;" name="edateStart">
<label for="dateEnd">au:</label>
<input type="date" class="#" id="dateEnd" style="width: 44%;" name="edateEnd">
</div>
<div class="form-group">
<label for="MontantP">Montant paye:</label>
<div class="input-group mb-3">
<input type="text" class="form-control" name="MontantP" placeholder="" id="MontantP">
<div class="input-group-append">
<span class="input-group-text">DH</span>
</div>
</div>
</div>
<div class="form-group">
<label for="RestP">Rest a paye paye:</label>
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="" id="MontantR" name="RestP">
<div class="input-group-append">
<span class="input-group-text">DH</span>
</div>
</div>
</div>
<p>
<a class="btn btn-primary" data-toggle="collapse" href="#multiCollapseExample1" role="button" aria-expanded="false" aria-controls="multiCollapseExample1" style="width: 100%">Bus subscribtion</a>
<div class="row">
<div class="col">
<div class="collapse multi-collapse" id="multiCollapseExample1">
<div class="card card-body">
<div class="form-group">
<div class="form-group">
<label for="TMontantP">Montant paye:</label>
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="" id="TMontantP" name="TransportP">
<div class="input-group-append">
<span class="input-group-text">DH</span>
</div>
</div>
</div>
<div class="form-group">
<label for="TRestP">Rest a paye paye:</label>
<div class="input-group mb-3">
<input type="text" class="form-control" placeholder="" id="TRestP" name="TransportR">
<div class="input-group-append">
<span class="input-group-text">DH</span>
</div>
</div>
</div>
<div class="form-group">
<label for="TdateStart"></label>
<input type="date" class="#" id="TdateStart" style="width: 48%;" name="TdateStart">
<label for="dTateEnd">au:</label>
<input type="date" class="#" id="TdateEnd" style="width: 44%;" name="TdateEnd">
</div>
</div>
</div>
</div>
</div>
</div>
</p>
<br>
<button type="submit" class="btn btn-secondary">Submit</button>
</form>
</div>
</div>
</div>
</div>
</div>
#else
<div class="d-flex justify-content-center text-center">
<div class="alert alert-danger" role="alert" style="width: 70%">
identifié vous d'abord
</div>
</div>
#endauth
#endif
#endsection
Looks like your foreign key constraint isn't setup correctly. From the look of the error you have setup payment_agrements.responsible_id to point to payment_agrements.id instead of responsibles.id.
In the migration for that table, that field probably looks like this:
$table->foreign('responsible_id')->references('id')->on('payment_agrements');
When it should be:
$table->foreign('responsible_id')->references('id')->on('responsibles');
I have tried and got help from stack overflow kind team member and reached till this level, yet I have to go step closer to solve it .However, when
I am trying to pass parameter that is concatenated, example I pass parameter like l/59. Once this parameter is passed, it should retrieve relevant data from table named st_dak_details , and I want data retrieved from that table to populate it in another view page . But it is not working, meaning not getting populated.
first view page where I pass parameter
<div class="col-sm-7 col-md-6 col-lg-4">
<button type="reset" class="btn btn-default" >Reset <span class="glyphicon glyphicon-refresh"></span></button>
<button type="button" class="btn btn-success" id="getbtn" onclick="loadPagcontente('<?php echo site_url()?>/UsermanagementController/forwardtrack')" >Get Detais <span class="glyphicon glyphicon-ok"></span></button>
<!-- <button type="button" class="btn btn-success" id="getbtn" onclick="loadPagcontente('<?php //echo site_url()?>/UsermanagementController/forwardtrack')">Get Detais <span class="glyphicon glyphicon-ok"></span></button> -->
</div>
Inside Controller
function forwardtrack($param='',$param2='') {
if(sizeof($this->db->get_where('st_forward',array('letter_no' =>$param.'/'.$param2))->result_array())>0 && (!($param.'/'.$param2) )){
$data1['message']= 'notallow';
$this->load->view('track1',$data1);
}else{
$data1['name']=$this->db->get_where('bpas_user_profiles',array('AgencyMainParentID' =>$this->session->userdata('ministryId'),'AgencyParentID'=>$this->session->userdata('parentID'),'AgencyID'=>$this->session->userdata('agencyID')))->result_array();
$data1['userdeatils']=$this->ag->tracks($param.'/'.$param2);
$this->load->view('userManagement/forward2', $data1);
}
/* ag=> agency model */
}
Inside model
public function tracks($letterno="")
{
$query= $this->db->get_where('st_dak_details',array('dakLetterNo'=>$letterno));
if ($query->num_rows() > 0) {
return $query->row();
} else {
return array();
}
}
Inside final view page
<div class="container">
<div class="panel panel-info">
<div class="panel-heading">
<i class="fa fa-envelope-o fa-fw"></i>forward to
</div>
<div class="panel-body">
<form class="form-horizontal" enctype="multipart/form-data" action="#" method="post" id="forwardmessage">
<div class="form-group">
<label for="letter"class="col-xs-12 col-lg-1 col-sm-1 col-md-1">letter_no: </label>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<?php if(!empty($userdeatils)){
foreach($userdeatils as $row) { ?>
<!-- your html code -->
<input name="dakLetterNo" id="dakLetterNo" value="<?php echo $row['dakLetterNo'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<!-- <div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">created: </label>
<div class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="copy_to" id="copy_to" value="<?php //echo $userdeatils->created;?>"readonly="true" class="form-control" type="text" required />
</div> -->
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2 control-label">Attachment: </label>
<div class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<input type="file" name="Attachment" id="Attachment">
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Subject: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon" id="subjecterr"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="subject" id="Remark" value="<?php echo $row['Remark'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Place: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="place" id="place" value="<?php echo $row['place'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">from: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="from" id="receieve_add" value="<?php echo $row['receieve_add'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Created: </label>
<div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span>
<input name="created" id="created" value="<?php echo $row['created'];?>"readonly="true" class="form-control" type="text" required />
</div>
</div>
<!-- </div> -->
<!-- <div class="form-group"> -->
<!-- <label class="col-xs-12 col-lg-2 col-sm-2 col-md-2">Message: </label> -->
<!-- <div class="input-group" class="col-xs-12 col-lg-10 col-sm-10 col-md-10"> -->
<!-- <span class="input-group-addon"><i class="glyphicon glyphicon-credit-card"></i></span> -->
<!-- <input name="message" id="message" value="<?php //echo $userdeatils->created;?>"readonly="true" class="form-control" type="text" required /> -->
<!-- </div> -->
<!-- </div> -->
<?php } ?> <!-- //foreach close -->
<?php } ?> <!-- //if close -->
<div class="form-group">
<label class="col-lg-2 col-xs-12 col-sm-2 col-md-2">Message: </label>
<div class="col-xs-12 col-lg-10 col-sm-10 col-md-10">
<textarea class="form-control" id="message" name="message"></textarea>
<span id="messageerr" class="text-danger"></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 col-xs-12 col-sm-2 col-md-2">
Forward to
</label>
<div class="col-lg-6 col-xs-12 col-sm-6 col-md-6">
<select name="forwardto[]" id="agency" class="form-control">
<option value="">Select</option>
<?php
foreach($name as $row): ?>
<option value="<?php echo $row['cid']?>">
<?php echo $row['FirstName'].$row['MiddleName'].$row['LastName']?>
</option>
<?php endforeach;?>
</select>
<span id="forwarderr" class="text-danger"></span>
</div>
<div class="col-lg-4 col-xs-12 col-sm-4 col-md-4">
<button type="button" onclick="addmessageto()" class="btn btn-success">Add More</button>
<button type="button" onclick="removemessageto()" class="btn btn-warning">Remove</button>
</div>
</div>
<span id="addmoreforwardto"></span>
<hr />
<div class="form-group">
<div class="col-xs-12 col-lg-10 col-sm-12 col-md-12">
<button type="button" class="btn btn-info" onclick="forwardmessage('forward')"> <i class="fa fa-send"></i> Forward to</button>
<button type="button" class="btn btn-info" onclick="forwardmessage('complete')"> <i class="fa fa-send"></i> Complete Action</button>
<a href="<?php echo base_url()?>index.php/Settings/view_ods_dashboard/"> <button type="button" class="btn btn-warning">
<i class="fa fa-dashboard" aria-hidden="true" ></i> Dashboad</span>
</button>
</a>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
I expect concatenated parameter that I passed from first view page to retrieve data from table and populate it into the final view page.
If you have data like l/54 or l/59 with varchar datatype column then below query will work.
public function tracks($letterno="")
{
//$query= $this->db->get_where('st_dak_details',array('dakLetterNo'=>$letterno));
$this->db->select('*');
$this->db->from('st_dak_details');
$this->db->like('dakLetterNo', $letterno); //'%l/54%'
$query= $this->db->get();
if ($query->num_rows() > 0) {
return $query->result_array();
} else {
return array();
}
}
I'm getting an error as "Name and email address are required if not a client" while running the below mentioned code.
Find below the Controller Code:
class UserController extends Controller
{
public function insertform(){
return view('test');
}
public function create(){
$user=Whmcs::AddClient([
'firstname' => Input::get('firstname'),
'lastname' => Input::get('lastname'),
'email' => Input::get('email'),
'address1' => Input::get('address1'),
'city' => Input::get('city'),
'state' => Input::get('state'),
'postcode' => Input::get('postcode'),
'country' => Input::get('country'),
'phonenumber' => Input::get('phonenumber'),
'password2' => Input::get('password2'),
]);
return $user;
}
}
Find below the route code:
Route::get('insert', 'UserController#insertform');
Route::post('create', 'UserController#create')->name('user.create');
The blade file is given below
<div id="content" class="app-content" role="main">
<div class="app-content-body ">
<div class="bg-light lter b-b wrapper-md">
<h1 class="m-n font-thin h3">Sign up</h1>
</div>
<div class="wrapper-md" ng-controller="FormDemoCtrl">
<div class="row">
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading font-bold">create an account</div>
<div class="panel-body">
<form class="bs-example form-horizontal" action="
{{route('user.create')}}" method="post">
<input type = "hidden" name = "_token" value = "<?php echo
csrf_token(); ?>">
<div class="form-group">
<label class="col-lg-2 control-label">firstname</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="firstname"
placeholder="Name">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">lastname</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="lastname"
placeholder="Name">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">Email</label>
<div class="col-lg-6">
<input type="email" class="form-control" name="email"
placeholder="Email">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">address1</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="address1"
placeholder="Subject">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">city</label>
<div class="col-lg-6">
<select class="form-control" name="city">
<option value="-- Select --">-- Select --</option>
<option value="Coimbatore">Coimbatore</option>
<option value="Chennai">Chennai</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">state</label>
<div class="col-lg-6">
<select class="form-control" name="state">
<option value="-- Select --">-- Select --</option>
<option value="Tamilnadu">Tamilnadu</option>
<option value="Andhra">Andhra</option>
<option value="Karnataka">Karnataka</option></select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">country</label>
<div class="col-lg-6">
<select class="form-control" name="country">
<option value="-- Select --">-- Select --</option>
<option value="India">India</option>
<option value="China">China</option>
<option value="Australia">Australia</option></select>
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">postcode</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="postcode"
placeholder="postcode">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">phonenumber</label>
<div class="col-lg-6">
<input type="text" class="form-control" name="phonenumber"
placeholder="phonenumber">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label">password</label>
<div class="col-lg-6">
<input type="password" class="form-control" name="password2"
placeholder="password">
</div>
</div>
<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<button type="submit" class="btn btn-sm btn-
success">Login</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
When I run the above code I'm getting an error as below:
{"result":"error","message":"Name and email address are required if not a client"}
suggest me a solution to solve this and post the data in laravel.
I am working on Laravel Form data Updation with image update. Now here my image only update smoothly in my DB. But other field does not update. anyone can identify what is my mistake? i attached my code below:
Controller
public function siteadmin_update_ads(Request $request)
{
$post = $request->all();
$cid=$post['id'];
$name = $post['ads_title'];
$url = $post['ads_url'];
$img=Input::file('ads_image');;
$v=validator::make($request->all(),
[
'ads_title'=>'required',
'ads_url' => 'required',
'ads_image'=> 'required'
]
);
if($v->fails())
{
return redirect()->back()->withErrors($v->errors());
}
else
{
if($img->isvalid())
{
$extension=$img->getClientOriginalName();
$move_img = explode('.',$extension);
$fileName=$move_img[0].str_random(8).".".$move_img[1];
$destinationPath = '../assets/adsimage/';
$uploadSuccess=Input::file('ads_image')->move($destinationPath,$fileName);
$data=array(
'ads_title'=> $name,
'ads_url'=> $url,
'ads_image'=>$fileName,
);
$i=Ads_model::update_ads($data,$cid);
if($i>0)
{
Session::flash ('message_update', 'Record Updated Successfully');
return redirect('siteadmin_manageads');
}
}
else {
return Redirect('siteadmin_editads');
}
}
}
Model
public static function update_ads($data,$cid)
{
return DB::table('le_ads')->where('id',$cid)->update($data);
}
View
<form class="form-horizontal form-label-left" id="myform" novalidate method="POST" action="{{action('SiteadminController#siteadmin_update_ads')}}" enctype="multipart/form-data">
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
<input type="hidden" class="form-control" name="id" value="<?php echo $row->id ?>" id="id">
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Ad Title<span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input id="name" class="form- control col-md-7 col-xs-12" data-validate-length-range="3" name="ads_title" placeholder="Ad Title" required type="text" value="<?php echo $row->ads_title ?>">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Upload Image*</label>
<div class="col-md-9 col-sm-6 col-xs-12">
<input type='file' id="field" class='demo left' name='ads_image' data-type='image' data-max-size='2mb'/><br>
<img src="{{ url('../assets/adsimage/').'/'.$row->ads_image}}" style="height:90px;">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="name">Redirect URL<span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input id="name" class="form-control col-md-7 col-xs-12" data-validate-length-range="3" name="ads_url" placeholder="Redirect URL" required type="url" value="<?php echo $row->ads_url ?>">
</div>
</div>
<div class="item form-group">
<div class="col-md-3"></div>
<div class="col-md-2 col-sm-6 col-xs-12">
<button class="btn btn-block btn-success" type="submit">Update</button>
</div>
<div class="col-md-2 col-sm-6 col-xs-12">
<button class="btn btn-block btn-danger" type="reset">Cancel</button>
</div>
</div>
</form>