How do i update the content in my database? - laravel

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

Related

Laravel csrf_field() Is Blank

I am learning about Packages in Laravel 5.4 and ultimately I will upload them to github.
This is my directory structure :
laravel
-vendor
--student
---myPackage
----src
-----Views
------myView.blade.php
the myView.blade.php has a form in it, and a {{csrf_field()}} function call, but when I inspect the output in the browser, the value attribute of the hidden input <input name="_token" value="" type="hidden"> is empty.
How do I make this work ?
SOLUTION
Apparantly, I needed to make sure that the web middleware is in use
for my routes, so I changed Route::get('/Register/{group}',
'Student\myPackage\Http\User#create'); to
Route::get('/Register/{group}',
'Student\myPackage\Http\User#create')->middleware('web');
Route:
Route::get('/Register/{group}', 'Student\myPackage\Http\User#create');
Route::post('/Register/{group}', 'Student\myPackage\Http\User#store');
Controller:
public function create($group){
return view('StudentUser::app', ['group' => $group]);
}
public function store($group)
{
dd(request()->all());
}
Form:
<form class="form-horizontal" role="form" method="POST" action="/Register/{{$group}}">
<div class="tab-content">
<div id="ap-about" class="tab-pane active">
{!! csrf_token() !!}
<div class="form-group">
<label for="name" class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control" name="name" value="" required autofocus>
</div>
</div>
<div class="form-group">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="" required>
</div>
</div>
<div class="form-group">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
</div>
</div>
<div class="form-group">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="button" class="btn btn-primary">
Next
</button>
</div>
</div>
</div>
<div id="ap-personal" class="tab-pane">
<div class="form-group">
<label for="address" class="col-md-4 control-label">Address</label>
<div class="col-md-6">
<input id="address" type="text" class="form-control" name="personal[]" value="" required autofocus>
</div>
</div>
<div class="form-group">
<label for="url" class="col-md-4 control-label">url</label>
<div class="col-md-6">
<input id="url" type="text" class="form-control" name="personal[]" value="" required autofocus>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Register
</button>
</div>
</div>
</div>
</div>
</form>

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();
}

how to write ckeditor code in laravel form view in laravel

Hello everyone i want to add ckeditor in my view which has multiple divs. How can i do that by adding this ckeditor code:
<title>A Simple Page with CKEditor</title>
<script src="../ckeditor.js"></script>
</head>
<body>
<form>
<textarea name="editor1" id="editor1" rows="10" cols="80">
This is my textarea to be replaced with CKEditor.
</textarea>
<script>
// Replace the <textarea id="editor1"> with a CKEditor
// instance, using default configuration.
CKEDITOR.replace( 'editor1' );
</script>
</form>
</body>
And this is my view
#extends('sadmin.main-template')
#section('title', 'Super admin Dashboard')
#section('title', 'Add Plan')
#section('content')
<div class="col-lg-9 col-md-9 col-sm-9 col-xs-12 right-sidebar admin-client add-client">
#include('partials.errors')
<form action="{{url('sadmin/add_plan')}}" class="toggle-disabled" method="post">
{!! csrf_field() !!}
<h3 class="title">Add a plan</h3>
<div class="form-group">
<label >You Can Create Your Plan Here</label>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 left-client-title">
<div class="form-group">
<label class="form-label name">
<span class="form-name">Name</span>
<input type="text" class="form-control" id="name" name="name" placeholder="" data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$">
</label>
</div>
<div class="form-group">
<label class="form-label name">
<span class="form-name">Price</span>
<input type="text" class="form-control" id="name" name="price" placeholder="" data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$">
</label>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 right-client-title">
<div class="form-group">
<label class="form-label name">
<span class="form-name">Allowed Users</span>
<input type="text" class="form-control" id="name" name="allowed_users" placeholder="" data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$">
</label>
</div>
<div class="form-group">
<label class="form-label name">
<span class="form-name">Can Trail</span>
<input type="text" class="form-control" id="canTrail" name="can_trail" placeholder="" data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$">
</label>
</div>
</div>
<div class="form-group">
<label class="form-label name">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 left-client-title">
<span class="form-name">Trail Duration</span>
<input type="text" class="form-control" id="password" name="trail_duration" placeholder="" data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$">
</label>
<div class="form-group">
<label class="form-label name">
<span class="form-name">Detail 1</span>
<input type="text" class="form-control" id="passwordConfirmation" name="detail1" placeholder="" data-validation="custom" data-validation="required">
</label>
</div>
</div>
<div class="form-group">
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 right-client-title">
<label class="form-label name">
<span class="form-name">Detail 2</span>
<input type="text" class="form-control" id="phoneNumber" name="detail2" placeholder="" data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$">
</label>
<div class="form-group">
<label class="form-label name">
<span class="form-name">Staff Profiles</span>
<input type="text" class="form-control" id="planName" name="staff_profiles" placeholder="" data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$">
</label>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 left-client-title">
<div class="form-group">
<label class="form-label name">
<span class="form-name">Space Management</span>
<input type="text" class="form-control" id="planPrice" name="space_management" placeholder="" data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$">
</label>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 right-client-title">
<div class="form-group">
<label class="form-label name">
<span class="form-name">Currency Unit</span>
<input type="text" class="form-control" id="allowedUsers" name="currency_unit" placeholder=""data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$" >
</label>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 right-client-title">
<div class="form-group">
<label class="form-label name">
<span class="form-name">Location charges</span>
<input type="text" class="form-control" id="allowedUsers" name="location_charges" placeholder=""data-validation="custom" data-validation-regexp="^([A-Za-z ]+)$" >
</label>
</div>
</div>
</div>
<p> </p>
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 text-center">
<div align="center">
<button type="submit" class="btn btn-success" style="padding-left:90px; padding-right:90px;"><strong>Submit</strong></button>
</div>
</div>
</div>
</section>
</div>
#endsection
How i can apply ckeditor code in each div any help would be appreciated.

Fields does not Update in laravel5

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>

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