Fields does not Update in laravel5 - laravel-5

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>

Related

Insert data from modal, Codeigniter

I'm trying to insert the input data from a modal but I don't know how to achieve this. I'm not really familiar with AJAX(I apologize for that). I did some readings and research but I'm getting confused. Here is my modal content reserve_form.php
<form action="" id="book-form">
<div class="row flex-lg-row-reverse align-items-center pt-1">
<h3>Reservation Details</h3>
<div class="col-10 col-sm-8 col-lg-6">
<input type="hidden" name="package_id" value="<?php ?>">
<div class="form-group">
<label for="date_start" class="control-label">Reserve Date:</label>
<input type="date" name="date_start" id="date_start" class="form-control form-conrtrol-sm rounded-0" min="<?php echo date("Y-m-d") ?>" value="<?php echo date("Y-m-d") ?>" required>
</div>
<div id="msg" class="text-danger"></div>
<div id="check-availability-loader" class="d-none">
<center>
<div class="d-flex align-items-center col-md-6">
<strong>Checking Availability...</strong>
<div class="spinner-border ml-auto" role="status" aria-hidden="true"></div>
</div>
</center>
</div>
<div class="form-group">
<label for="quantity" class="control-label">Number of Person <span><i>(Max. of 15 person)</i></span></label>
<input type="number" class="form-control form" required name="person" value="">
</div>
<div class="form-group">
<label for="amount" class="control-label">Additional Inclusions</label>
<div>
<input type="checkbox" id="inclusion" name="inclusion" value="">
<label for="inclusion"> Unlimited Samgyupsal & Al Fresco dining experience</label>
</div>
</div>
<div class="form-group">
<label for="amount" class="control-label">Total Amount</label>
<input type="number" name="cost" id="amount" class="form-control form-conrtrol-sm rounded-0 text-right" value="<?php echo isset($cost) ? number_format($cost, 2) : 0.00 ?>" required readonly>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label for="name" class="control-label">First Name</label>
<input type="text" class="form-control mb-3" name="firstname" placeholder="Enter First Name" value="">
</div>
<div class="form-group">
<label for="name" class="control-label">Last Name</label>
<input type="text" class="form-control mb-3" name="lastname" placeholder="Enter Last Name" value="">
</div>
<div class="form-group">
<label for="name" class="control-label">Contact</label>
<input type="text" class="form-control mb-3" name="contact" placeholder="09xx-xxx-xxxx" value="">
</div>
<div class="form-group">
<label for="name" class="control-label">Email</label>
<input type="text" class="form-control mb-3" name="email" placeholder="example#email.com" value="">
</div>
</div>
</div>
<div class="modal-footer py-2">
<button class="btn btn-warning" type="submit" name="details">Save</button>
<button class="btn btn-secondary "><span class="close-sm">Close</span></button>
</div>
</form>
Here's my modal in view.php
<!-- Modal content -->
<div class="modal-content">
<div class="modal-header py-1">
<h3><?php echo $packages->title; ?></h3>
</div>
<div class="modal-body py-2">
<?php $this->load->view('forms/reserve_form'); ?>
</div>
</div>
Here' my Controller(page.php)
public function reservation_details()
{
$details = array();
$details2 = array();
if ($this->input->post('details')) {
$this->form_validation->set_rules('firstname', 'First Name', 'required');
$this->form_validation->set_rules('lastname', 'Last Name', 'required');
$this->form_validation->set_rules('contact', 'Contact', 'required');
$this->form_validation->set_rules('email', 'Email', 'required');
$this->form_validation->set_rules('date_start', 'Reserve Date', 'required');
$this->form_validation->set_rules('person', 'Number of Person', 'required|max_length[15]');
if ($this->form_validation->run() == true) {
$details = array(
'firstname' => $this->input->post('firstname'),
'lastname' => $this->input->post('lastname'),
'contact' => $this->input->post('contact'),
'email' => $this->input->post('email'),
);
$this->UI_model->reserve_details($details);
$details2 = array(
'date_start' => $this->input->post('date_start'),
'person' => $this->input->post('person'),
'inclusion' => $this->input->post('inclusion'),
);
$this->UI_model->reserve_add($details2);
}
}
}
Here's the Model
public function reserve_details(){
if (!empty($data)) {
$this->db->insert('clients', $data);
return $this->db->insert_id();
}
return false;
}
public function reserve_add(){
if (!empty($data)) {
$this->db->insert('book_list', $data);
return $this->db->insert_id();
}
return false;
}
Also, I'm trying to insert the data for multiple tables. Any help will be much appreciated. Thanks! Is is also fine to place the submit button at modal footer? or it should be at reserve.php?
You're passing data array through these functions.
$this->UI_model->reserve_details($details);
$this->UI_model->reserve_add($details2);
But in the model, you're not catching those.
public function reserve_details(){
public function reserve_add(){
So it should be
public function reserve_details($data){
public function reserve_add($data){
Since you're checking if (!empty($data)) { its always retuns false, unless Undefixed Varibale error.

How do i update the content in my database?

I am trying to update values I got from the database but it seems not to be going to the routes function
I tried changing the routes method and even die down the request but it seems not to work
Here is the route
Route::put("/users/bonus/update/{id}",
[
"uses" => "AdminDashboardController#updatebonus",
"as"=> "userbonus.mer"
]);
below is the function that is been called to update
public function updatebonus(Request $request, $id)
{
if (auth()->user()->isAdmin != 1) {
return redirect()->route('home');
} else if (auth()->user()->isAdmin == 1) {
$bonus=OtherBonus::where('id','=','$id')->first();
$bonus->card_bonus=trim(strip_tags($request['cbonus']));
$bonus->monthly_bonus=trim(strip_tags($request['mbonus']));
$bonus->travelling_bonus=trim(strip_tags($request['tbonus']));
$bonus->festival_bonus=trim(strip_tags($request['fbonus']));
$bonus->save();
return redirect()->back()->with("success", "Bonus Settings
Successfully updated");
}
}
below is the form that passes the data to the function which communicates with the database.
<form class="form-horizontal form-label-left" action="{{route('userbonus.mer', ['id'=>$bonus['id']])}}" method="PUT">
<span class="section">General Bonus in %age</span>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="cbonus">Card
Bonus <span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input class="form-control col-md-7 col-xs-12"
value="{{$bonus['card_bonus']}}" name="cbonus"
placeholder="10.00%" required="required" type="text">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="fbonus">Festival
Bonus<span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" name="fbonus" required="required"
value="{{$bonus['festival_bonus']}}"
class="form-control col-md-7 col-xs-12" placeholder="34.6%">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="mbons">Monthly
Bonus <span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" id="email" name="mbonus" required="required"
value="{{$bonus['monthly_bonus']}}" placeholder="56.9%"
class="form-control col-md-7 col-xs-12">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="tbonus">Travelling
Bonus <span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" id="email" name="tbonus" placeholder="0.89%"
value="{{$bonus['travelling_bonus']}}" required="required"
class="form-control col-md-7 col-xs-12">
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<button type="reset" class="btn btn-primary">Reset</button>
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
The HTML form doesn't accept PUT as method. It only works with GET and POST. Have a look here. So if you write
<form method="PUT"></form>
you're going to submit the form as a GET request. Laravel listens for a specific input that has to present after form submission in order to recognize the PUT method. Have a look at the official documentation
HTML forms do not support PUT, PATCH or DELETE actions. So, when defining PUT, PATCH or DELETE routes that are called from an HTML form, you will need to add a hidden _method field to the form. The value sent with the _method field will be used as the HTTP request method:
<form action="/foo/bar" method="POST">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
You may use the #method Blade directive to generate the _method input:
<form action="/foo/bar" method="POST">
#method('PUT')
#csrf
</form>
Try This
public function updatebonus(Request $request, $id)
{
if (auth()->user()->isAdmin != 1) {
return redirect()->route('home');
} else if (auth()->user()->isAdmin == 1) {
$bonus=OtherBonus::find($id);
$bonus->update([
'monthly_bonus'=>$request->mbonus,
'travelling_bonus'=>$request->tbonus,
'festival_bonus'->$request->fbonus;
]);
return redirect()->back()->with("success", "Bonus Settings
Successfully updated");
}
}
And BLADE FILE JUST CHANGE METHOD TO post & and after this add {{method_field('PUT')}}
{{csrf_field()}}
<form class="form-horizontal form-label-left" action="{{route('userbonus.mer', ['id'=>$bonus['id']])}}" method="post">
{{method_field('PUT')}}
{{csrf_field()}}
<span class="section">General Bonus in %age</span>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="cbonus">Card
Bonus <span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input class="form-control col-md-7 col-xs-12"
value="{{$bonus['card_bonus']}}" name="cbonus"
placeholder="10.00%" required="required" type="text">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="fbonus">Festival
Bonus<span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" name="fbonus" required="required"
value="{{$bonus['festival_bonus']}}"
class="form-control col-md-7 col-xs-12" placeholder="34.6%">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="mbons">Monthly
Bonus <span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" id="email" name="mbonus" required="required"
value="{{$bonus['monthly_bonus']}}" placeholder="56.9%"
class="form-control col-md-7 col-xs-12">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="tbonus">Travelling
Bonus <span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" id="email" name="tbonus" placeholder="0.89%"
value="{{$bonus['travelling_bonus']}}" required="required"
class="form-control col-md-7 col-xs-12">
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-3">
<button type="reset" class="btn btn-primary">Reset</button>
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>
In Route make it post

how to fix,"Call to a member function row() on null "

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

how to select and show data comment by id post in codeigniter

master peace of codeigniter. im new user for this framework.
i have problem to show comment data by id_diskusi in the single post of diskusi. i try to show data using 'where' in the lybrary code but its still not show the data. i hope the people at there can help me & solved this problem.
i use library to get data from database
public function setuju(){
$data=$this->CI->db->query("SELECT komentar.id AS id,
komentar.diskusi_id AS id_diskusi,
komentar.pilih AS pilih,
komentar.nama AS nama,
komentar.email AS email,
komentar.pesan AS pesan,
komentar.tanggal AS tanggal,
diskusi.diskusi_id as nomor_diskusi
FROM diskusi, komentar
WHERE diskusi.diskusi_status='publish' AND komentar.pilih='1' AND komentar.diskusi_id=diskusi.diskusi_id ORDER BY komentar.id DESC
");
return $data->result_array();
}
i use this code to filter data who data on komentar will be show by id of diskusi.
komentar.diskusi_id=diskusi.diskusi_id
but still not work
and its my controller
$data['setuju']=$this->diskusi->setuju();
code in the view
<div id="netral" class="tab-pane">
<?php
foreach ($netral AS $value) {
echo "<div class='box box-body no-border'>
<div class='row'>
<div class='col-md-2'>
<div class='box-profile'>"; ?>
<img alt='user image' style='margin-top:10px' class='profile-user-img img-responsive img-circle' src='<?php echo img_user_url('user.png'); ?>'>
<?php echo"
<h3><center>$value[nama]</center</h3>
</div>
</div>
<div class='col-md-10'>
<div class='callout callout-danger lead'><span class='pull-right'>".format_tanggal($value['tanggal'])."</span><br>
<p>$value[pesan]</p>
</div>
</div>
</div>
</div>";
}?>
</div><!-- /.tab-pane -->
<div class="box box-danger">
<div class="box-header with-border">
<div class="user-block">
<h3 class="no-margin">Tinggalkan Komentar</h3>
</div><!-- /.user-block -->
<div class="box-tools">
<button data-widget="collapse" class="btn btn-danger btn-sm"><i class="fa fa-minus"></i></button>
</div><!-- /.box-tools -->
</div>
<div class="box-body">
<form method='POST' id='komentar' action='<?php echo baseURL('form_visitors/komentar'); ?>' autocomplete='off' method="post" class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label" for="inputName">Name</label>
<div class="col-sm-10">
<input type="hidden" name="diskusi_id" value="<?php echo "$diskusi[id]";?>">
<input type="text" placeholder="Nama" data-original-title="Masukkan Nama" required='required' name="nama" id="inputName" class="form-control">
<input type='hidden' class='form-control' name='url' value='<?php echo current_url() ?>' />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="inputEmail">Email</label>
<div class="col-sm-10">
<input type="email" name="email" data-original-title="Masukkan Email" placeholder="Email" required='required' id="inputEmail" class="form-control">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"></label>
<div class="col-sm-10">
<div class="checkbox">
<label>
<input type="radio" name="pilih" value="1"> <i class="fa fa-thumbs-o-up margin-r-5 text-green"> <b>Setuju</b></i>
</label>
<label>
<input type="radio" name="pilih" value="2"> <i class="fa fa-square margin-r-5 text-yellow"> <b>Netral</b></i>
</label>
<label>
<input type="radio" name="pilih" value="3"> <i class="fa fa-thumbs-o-down margin-r-5 text-red"> <b>Tidak Setuju</b></i>
</label>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label" for="inputExperience">Komentar</label>
<div class="col-sm-10">
<textarea placeholder="Komentar" name="pesan" id="inputExperience" required='required' class="form-control"></textarea>
</div>
</div>
<div class='form-group'>
<label class="col-sm-2 control-label" for="inputExperience"></label>
<div class="col-sm-10">
<div id='recaptcha1'></div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button class="btn btn-danger" type="submit" id="submit">Submit</button>
<div class="cssload" style="display: none; width: 100px">
<div class="cssload-tube-tunnel"></div>
</div>
</div>
</div>
</form>
</div>
</div>
how can i show comment data according with single post of diskusi who have comment. Thank you very much in advance! sorry for my english.
I can see you are fetching the data from two different tables but you have not used 'JOIN'.
you can try the following query string :
public function setuju(){
$data=$this->CI->db->query("SELECT komentar.id AS id,
komentar.diskusi_id AS id_diskusi,
komentar.pilih AS pilih,
komentar.nama AS nama,
komentar.email AS email,
komentar.pesan AS pesan,
komentar.tanggal AS tanggal,
diskusi.diskusi_id as nomor_diskusi
FROM komentar, diskusi
JOIN diskusi
ON diskusi.diskusi_id=komentar.diskusi_id
WHERE diskusi.diskusi_status='publish' AND komentar.pilih='1' ORDER BY komentar.id DESC
");
return $data->result_array();
}

Call to a member function isvalid() on null in laravel5

When Update an image, it shows follwing error. I cannot update this laravel5 form. can any one find what is my mistake?
FatalErrorException in SiteadminController.php line 308:
Call to a member function isvalid() on null
My file are
Controller
public function siteadmin_update_product(Request $request)
{
$post = $request->all();
$cid=$post['product_id'];
$product_title = $request->input('product_title');
$product_price = $request->input('product_price');
$product_discount_price = $request->input('product_discount_price');
$product_qty = $request->input('product_qty');
$deal_description = $request->input('deal_description');
$select_merchant = $request->input('select_merchant');
$select_shop = $request->input('select_shop');
$product_meta_keyword = $request->input('product_meta_keyword');
$product_meta_description = $request->input('product_meta_description');
$spec_type = $request->input('spec_type');
$specification = $request->input('specification');
$product_size = $request->input('product_size');
$product_image=Input::file('product_image');
$v =validator::make($request->all(),
[
]
);
if($v->fails())
{
return redirect()->back()->withErrors($v->errors());
}
else
{
if($product_image->isvalid())
{
$extension=$product_image->getClientOriginalName();
$move_img = explode('.',$extension);
$fileName=$move_img[0].str_random(8).".".$move_img[1];
$destinationPath = '../assets/productimage/';
$uploadSuccess=Input::file('product_image')->move($destinationPath,$fileName);
$data = array(
'product_title' => $product_title,
'product_price' => $product_price,
'product_discount_price' => $product_discount_price,
'product_qty' => $product_qty,
'select_merchant' => $select_merchant,
'select_shop' => $select_shop,
'product_meta_keyword' => $product_meta_keyword,
'product_meta_description' => $product_meta_description,
'spec_type' => $spec_type,
'specification' => $specification,
'product_size' => $product_size,
'product_image'=> $fileName,
);
$ch=Product_model::update_product($data,$cid);
//$ch=DB::table('le_banner')->where('banner_id',$post['id'])->update($data);
if($ch > 0)
{
Session::flash ('message_update', 'Record Updated Successfully');
return redirect('siteadmin_manageproduct');
}
else
{
return Redirect('siteadmin_editproduct');
}
}
}
}
Model
public static function update_product($data,$cid)
{
return DB::table('le_product')->where('product_id',$cid)->update($data);
}
View:
<form class="form-horizontal form-label-left" enctype="multipart/form-data" novalidate action="{{action('SiteadminController#siteadmin_update_product')}}" method="POST">
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
<input type="hidden" class="form-control" name="product_id" value="<?php echo $row->product_id ?>" id="id">
<!-- text input -->
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Product Title*</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="product_title" placeholder="Product Title" required="required" type="text" value="<?php echo $row->product_title ?>">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="heard">Select Main Category<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select id="heard" class="form-control" required>
<option value="press">option 1</option>
<option value="net">option 2</option>
<option value="mouth">option 3</option>
</select>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="heard">Select Sub Category<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select id="heard" class="form-control" required>
<option value="press">option 1</option>
<option value="net">option 2</option>
<option value="mouth">option 3</option>
</select>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="heard">Select Second Sub Category<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select id="heard" class="form-control" required>
<option value="press">option 1</option>
<option value="net">option 2</option>
<option value="mouth">option 3</option>
</select>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Product Quantity*</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="1" name="product_qty" placeholder="Product Quantity" required="required" type="number" value="<?php echo $row->product_qty ?>">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Original Price*</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input id="number" class="form-control col-md-7 col-xs-12" data-validate-length-range="2" name="product_price" placeholder="Original Price" required="required" type="number" value="<?php echo $row->product_price ?>">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Discounted Price*</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input id="number" class="form-control col-md-7 col-xs-12" data-validate-length-range="2" name="product_discount_price" placeholder="Discounted Price" required="required" type="number" value="<?php echo $row->product_discount_price ?>">
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-2 col-sm-3 col-xs-10"></label>
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="chkPassport">
<input type="checkbox" id="chkSelect" checked/> ( Including tax amount )
</label>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-10"></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="number" id="txtUsername" class="form-control col-md-7 col-xs-12" name="product_incometax" placeholder="Tax Amound" value="<?php echo $row->product_incometax ?>" />
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Shipping Amount*</label>
<label class="control-label col-md-2 col-sm-3 col-xs-12" for="chkNo">
<input type="radio" id="chkNo" name="chkPassPort" checked/>
Free
</label>
<label class="control-label col-md-2 col-sm-3 col-xs-12" for="chkYes">
<input type="radio" id="chkYes" name="chkPassPort" />
Amount
</label>
</div>
<div class="item form-group" id="dvPassport1" style="display: none">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Shipping Amount*</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="number" id="txtPassportNumber" class="form-control col-md-7 col-xs-12" value="<?php echo $row->product_shippement_amount ?>" name="product_shippement_amount"/>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="textarea">Description <span class="required">*</span>
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<textarea id="textarea" required="required" name="product_description" class="form-control col-md-7 col-xs-12" placeholder="Description" data-validate-length-range="20"><?php echo $row->product_description ?></textarea>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Want to add specification*</label>
<label class="control-label col-md-2 col-sm-3 col-xs-12" for="Yes">
<input type="radio" id="Yes" name="r4" />
Yes
</label>
<label class="control-label col-md-2 col-sm-3 col-xs-12" for="No">
<input type="radio" id="No" name="r4" checked/>
No
</label>
</div>
<div class="item form-group" id="dvPassport2" style="display: none">
<label class="control-label col-md-3 col-sm-2 col-xs-10">Specification*</label>
<div class="col-md-4 col-sm-6 col-xs-12">
<select id="txtPassportNumber1" class="form-control" required value="<?php echo $row->spec_type?>" name="spec_type">
<?php
foreach($specification as $roww)
{?>
<option value="<?php echo $roww->spec_id;?>"><?php echo $roww->specification_name;?></option>
<?php
}
?>
</select>
</div>
<div class="col-md-2 col-sm-6 col-xs-12">
<input type="text" id="txtPassportNumber1" class="form-control col-md-7 col-xs-12" required data-validate-length-range="3" value="<?php echo $row->specification ?>" name="specification"/>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="heard">Product Size<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select id="heard" class="form-control" required value="<?php echo $row->product_size ?>" name="product_size">
<?php
foreach($size as $roww)
{?>
<option value="<?php echo $roww->id;?>"><?php echo $roww->size;?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="states">Product Color*</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select id="colorselector" class="form-control">
<option value="red">Red</option>
<option value="yellow">Yellow</option>
<option value="blue">Blue</option>
</select>
</div>
</div>
<div class="item form-group">
<div class="output">
<label class="control-label col-md-3 col-sm-3 col-xs-12"></label>
<div id="red" class="colors red"> <input type="checkbox" checked/>RED </div>
<div id="yellow" class="colors yellow"> <input type="checkbox" checked/> YELLOW</div>
<div id="blue" class="colors blue"><input type="checkbox" checked/> BLUE</div>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Delivery Days*</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="number" class="form-control" placeholder="Delivery Days" name="product_days" required value="4" value="<?php echo $row->product_days ?>">
Eg : (2-5)
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="heard">Select Merchant<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select id="heard" class="form-control" required value="<?php echo $row->select_merchant ?>" name="select_merchant">
<?php
foreach($merchant as $roww)
{?>
<option value="<?php echo $roww->merchant_id;?>" >
<?php echo $roww->merchant_firstname;?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="heard">Select Shop<span class="required">*</span></label>
<div class="col-md-6 col-sm-6 col-xs-12">
<select id="heard" class="form-control" required value="<?php echo $row->select_shop ?>"
name="select_shop">
<?php
foreach($merchant as $roww)
{?>
<option value="<?php echo $roww->store_id;?>" >
<?php echo $roww->store_name;?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="textarea">Meta Keywords
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<textarea id="textarea" name="product_meta_keyword" class="form-control col-md-7 col-xs-12" placeholder="Meta Keywords"><?php echo $row->product_meta_keyword ?></textarea>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="textarea">Meta Description
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<textarea id="textarea" name="product_meta_description" class="form-control col-md-7 col-xs-12" placeholder="Meta Description"><?php echo $row->product_meta_description ?></textarea>
</div>
</div>
<div class="item form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12" for="textarea">Product Image </label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="file" name="product_image" value=""><br>
<img src="{{ url('../assets/productimage/').'/'.$row->product_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="textarea">Product Image </label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="file" name="product_image" value=""><br>
<img src="{{ url('../assets/productimage/').'/'.$row->product_second_image}}" style="height:90px;">
</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>
You have two file inputs with the name product_image. That's why your file is empty, and isValid() throws an error. You can use hasFile() to avoid exceptions like that.
replace
Input::file('image')->isValid()
to
Input::hasFile('image')

Resources