Controller Update method is not working in laravel - laravel-5

I am using laravel 5.2. Controller method store, show, and edit is working fine but update method is not working.
edit.blade is as:
#extends ('layouts.backend')
#section ('content')
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('backend.index') }}"> Back</a>
</div>
<form method="PATCH" action="{{ route('backend.update', $reports->id) }}">
<div>
create report
</div>
<div>
<table>
<tr>
<td>
<div class="form-group required">
<label for="category_id" class="control-label">ID</label>
<input class="form-control" name="id" id="id" type="text" value="{{ $reports->id}}">
</div>
<div class="form-group required">
<label for="category_id" class="control-label">Category</label>
<select class="form-control" id="category" name="category"><option value="" selected="selected">Select</option><option value="1">Agriculture</option><option value="2">Food</option><option value="3">Beverage</option></select>
</div>
<div class="form-group required">
<label for="name" class="control-label">Name</label>
<input class="form-control" name="name" id="name" type="text" value="{{ $reports->name}}">
</div>
<div class="form-group required">
<label for="url" class="control-label">Url</label>
<input class="form-control" name="slug" id="slug" type="text" value="{{ $reports->slug}}">
</div>
<div class="form-group required">
<label>Brief Description</label></br>
<textarea id="brief_des" name="brief_des" rows="12" cols="70" style="width: 80%" >
{{ $reports->brief_des}}
</textarea>
</div>
<div class="form-group required">
<label>Full Description</label></br>
<textarea id="full_des" name="full_des" rows="12" cols="70" style="width: 80%">
{{ $reports->full_des}}
</textarea>
</div>
<input type="submit" value="Update"/>
</td>
<td>
</td>
</tr>
</table>
</div>
{{ Form::token() }}
</form>
#endsection
and Controller update method code is as:
public function update(Request $request, $id){
report::find($id)->update($request->all());
return redirect()->route('backend.index')
->with('success','Product Updated Successfully');
}
and route.php is as:
Route::resource('backend', 'ReportController');
when I am submitting the form then I am getting any update in my database and redirect is not working also.

Related

PHP Laravel Post action

I have a form page for users informations update but my post function isn't working.I have defined a post method in the blade page and I show the page as a formaction post.This is my code;
#extends('layouts.admin-master')
#section('content')
<form action="post">
<div class="form-row">
<div class="form-group">
<label for="inputAddress2">Ad Soyad</label>
<input type="text" class="form-control" id="inputAddress2" name="name" value="{{ Auth::user()->name }}">
</div>
<br><br>
<div class="form-group">
<label for="inputAddress2">Şirket</label>
<input type="text" class="form-control" id="inputAddress2" name="company">
</div>
</div>
<div class="form-group">
<label for="inputAddress">Email</label>
<input type="text" class="form-control" id="inputAddress" name="email" value="{{ Auth::user()->email }}">
</div>
<div class="form-group">
<label for="inputAddress2">Telefon</label>
<input type="text" class="form-control" id="inputAddress2" name="phone">
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputState">Üyelik Tipi</label>
<select id="inputState" class="form-control">
<option selected>Seçenekler</option>
<option>Bronz Üyelik</option>
<option>Silver Üyelik</option>
<option>Gold Üyelik</option>
</select>
</div>
<div class="form-group col-md-2">
<label class="radio-container m-r-55">Tedarikçi
<input type="radio" checked="checked" name="secim" value="tedarikci">
<span class="checkmark"></span>
</label>
`enter code here` <label class="radio-container">Alıcı
<input type="radio" name="secim" value="alici">
<span class="checkmark"></span>
</label>
</div>
</div>
<form action="{{route('form.add')}}" method="post" enctype="multipart/form-data">
<button type="submit" class="btn btn-primary">Kaydet</button>
</form>
</form>
#endsection
try this:
#extends('layouts.admin-master')
#section('content')
<form action="{{route('form.add')}}" method="post" enctype="multipart/form-data">
<div class="form-row">
<div class="form-group">
<label for="inputAddress2">Ad Soyad</label>
<input type="text" class="form-control" id="inputAddress2" name="name" value="{{ Auth::user()->name }}">
</div>
<br><br>
<div class="form-group">
<label for="inputAddress2">Şirket</label>
<input type="text" class="form-control" id="inputAddress2" name="company">
</div>
</div>
<div class="form-group">
<label for="inputAddress">Email</label>
<input type="text" class="form-control" id="inputAddress" name="email" value="{{ Auth::user()->email }}">
</div>
<div class="form-group">
<label for="inputAddress2">Telefon</label>
<input type="text" class="form-control" id="inputAddress2" name="phone">
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="inputState">Üyelik Tipi</label>
<select id="inputState" class="form-control">
<option selected>Seçenekler</option>
<option>Bronz Üyelik</option>
<option>Silver Üyelik</option>
<option>Gold Üyelik</option>
</select>
</div>
<div class="form-group col-md-2">
<label class="radio-container m-r-55">Tedarikçi
<input type="radio" checked="checked" name="secim" value="tedarikci">
<span class="checkmark"></span>
</label>
`enter code here` <label class="radio-container">Alıcı
<input type="radio" name="secim" value="alici">
<span class="checkmark"></span>
</label>
</div>
</div>
<button type="submit" class="btn btn-primary">Kaydet</button>
</form>
put this line in your form and it should work :
{{csrf_field()}}
and make sure that your route address is correct too
u can add #csrf above the button

How to fetch data from database related to key using Laravel?

I am a beginner, and I want to show the value data into the input field related to the key but I am very confused that how can I show the value data into the input field so please if you have an idea please help me thanks.
Database table
Setting table https://ibb.co/jGFX4t2
I want to show a value data in this field, please see https://ibb.co/Mh08c9b
Settings Model
class Settings extends Model
{
protected $table="setting";
protected $fillable =['id','key','value'];
}
Controller
public function setting()
{
$setting=Settings::all();
return view('admin.setting.setting',compact('setting'));
}
HTML view
<form method="post" action="{{route('update.setting')}}" enctype="multipart/form-data" >
#csrf
<div class="card-box">
<div class="panel panel-heading">
<h3>Update Settings</h3>
</div>
<div class="col-lg-5">
<div class="mt-3">
<input type="file" name="logo_image" class="dropify" />
</div>
</div>
<div class="row">
<div class="col-lg-5 mt-3">
<div class="group-form">
<label>Contact Number*</label>
<input type="text" name="contact_number" value="{{ }}" class="form-control" >
</div>
</div>
<div class="col-lg-5 mt-3">
<div class="group-form">
<label>Contact Email *</label>
<input type="email" name="email" value="{{ }}" class="form-control" >
</div>
</div>
<div class="col-lg-10 mt-3">
<div class="group-form">
<label>Location *</label>
<input type="text" name="location" value="{{ }}" class="form-control" >
</div>
</div>
<div class="col-lg-5 mt-3">
<h3> Social Links:</h3>
<div class="group-form">
<label>Facebook *</label>
<input type="text" name="facebook" value="{{ }}" class="form-control" >
</div>
</div>
<div class="col-lg-5 mt-5">
<div class="group-form">
<label>Twitter *</label>
<input type="text" name="twitter" value="{{}}" class="form-control" >
</div>
</div>
<div class="col-lg-6 mt-3">
<div class="group-form">
<label>Linkedin *</label>
<input type="text" name="linkedin" value="{{}}" class="form-control" >
</div>
</div>
<div class="col-lg-7 mt-3">
<div class="group-form ">
<button type="submit" id="btnsubmit" class="btn btn-danger waves-effect waves-light col-lg-2">Save</button>
</div>
</div>
</div>
</div> <!-- end card-box -->
</form>
please use this code.
{{ $setting->Where('key', 'Contact_Email')->first()->value }}
How about something like:
{{ $setting->firstWhere('key', 'Contact_Number')->value; }}
{{ $setting->firstWhere('key', 'Contact_Email')->value; }}
{{ $setting->firstWhere('key', 'Location')->value; }}
etc
When you use Eloquent Model::all(), it returns a collection to the blade view.
Therefore you can use firstWhere to find the key value.

How to show a new column after using select2 in laravel?

I have a form and using select2 for filter. I want to show new column by using this select2.
I don't know its possible or not but i want to do this . using jquery or something, can someone reference to me about this? its my form for my input
<form class="form-prevent-multiple-submits" data-toggle="validator" action="{{route('update_sarpras_aduan'),'test'}} " method="post">
#csrf
{{method_field('patch')}}
<div class="form-group">
<label class="control-label" for="title">Nama Unit:</label>
<input type="text" name="nama_unit" id="nama_unit" class="form-control" data-error="Please enter title." required disabled/>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label" for="title">Tanggal Aduan:</label>
<textarea name="created_at" class="form-control" id="tgl_aduan" data-error="Please enter description." readonly ></textarea>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label class="control-label" for="title">Nama Pengadu:</label>
<input type="text" name="nama_pengadu" class="form-control" id="nama_pengadu" data-error="Please enter title." readonly />
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label> Isi Aduan </label>
<textarea name="aduan" id="aduan" class="form-control" rows="3" placeholder="Isi Aduan atau Keluhan ..." readonly ></textarea>
</div>
<div class="form-group">
<label class="control-label" for="title">Nama Teknisi:</label>
<input type="text" name="nama_teknisi" class="form-control" id="nama_teknisi" data-error="Please enter title." readonly />
<div class="help-block with-errors"></div>
</div>
----------------here this select2---------------------------
<div class="form-group">
<label>Pilih Inventaris</label>
<select class="form-control select2bs4" name="alat_id" id="alat_id" style="width: 100%;" aria-hidden="true">
#foreach($inven as $id => $item )
<option value="{{ $id }}">{{ $item }} </option>
#endforeach
</select>
</div>
--------------------------------------------------
<div class="form-group">
<label>Status Saat Ini (Jangan Lupa Diganti)</label>
<select name="status" id="status" class="form-control">
<option value="Tindakan Lanjutan">Tindakan Lanjutan</option>
<option value="Selesai">Selesai</option>
</select>
<div class="help-block with-errors"></div>
</div>
<div class="form-group">
<label> Tindakan Pelaksana </label>
<textarea name="tindakan" id="tindakan" class="form-control" rows="3" placeholder="Isi Tindakan Yang dilakukan" required ></textarea>
</div>
<div class="form-group">
<label>Kondisi Alat </label>
<select name="status_alat" id="status_alat" class="form-control">
<option value="Baik">Baik</option>
<option value="Rusak Ringan">Rusak Ringan</option>
<option value="Rusak Berat">Rusak Berat</option>
</select>
<div class="help-block with-errors"></div>
</div>
<input type="hidden" name="id" id="id" value="">
<input type="hidden" name="user_id" id="user_id" value="">
<input type="hidden" name="ipsrs_id" id="ipsrs_id" value="">
<input type="hidden" name="teknisi_id" id="teknisi_id" value="">
<input type="hidden" name="ended_at" id="ended_at" value="">
<div class="form-group">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
<button type="submit" id="button" class="btn btn-success crud-submit-edit button-prevent-multiple-submits">
<i class="spinner fa fa-spinner fa-spin" ></i>
Submit</button>
</div>
</form>
after using this select2 , will showing a new form . can someone references to me about this ?
//select input
<div class="form-group">
<label>Pilih Inventaris</label>
<select class="form-control select2bs4" name="alat_id" id="alat_id" style="width: 100%;" aria-hidden="true" onchange="Show()">
#foreach($inven as $id => $item )
<option value="{{ $id }}">{{ $item }} </option>
#endforeach
</select>
</div>
//new form
<div id="divid" style="display:none">
<form method="" action="">
#csrf
</form
<div>
//javascript code
<script>
function Show()
{
var fieldValue = $('#alat_id').val();
if(fieldValue == "")
{
document.getElementById("divid").style.display = 'none';
}
else{
document.getElementById("divid").style.display = 'inline'
}
}
</script>

in my laravel project some datas are not passed to controller from form submit.What could be the reasons?

in my laravel project i have made a form with input field name,size,price,etc. My problem is that when i type name in name field datas arenot passed to controller.This is happening only to some specific names.For some other names working fine.And this problem is raised in live in local working fine
below is form blade
<form class="form-horizontal form-label-left" method="post"
action="{{route('product')}}" enctype="multipart/form-data">
{{csrf_field()}}
<div class="form-group col-lg-6" >
<label for="select-from">Select Catagory:<span class="required" style="color:red;">*</span></label>
<select class="form-control" id="category" name="category">
<option value="">Choose</option>
#foreach($allcategory as $cat)
<option value="{{$cat->id}}">{{$cat->name}}</option>
#endforeach
</select>
</div>
<script type="text/javascript">
$(document).ready(function(){
$(document).on('change','#category',function(){
var a = $(this).val();
$.ajax({
type:'get',
url: '{{URL::to('#dashboard#/childcategory-section/submenu-choose')}}',
data:{'id':a},
success:function(datas){
$("select#submenu").empty();
$.each(datas,function(i,data){
$("select#submenu").append('<option value="'+data.id+'"> '+data.name+'</option>');
});
}
});
});
});
</script>
<div class="form-group col-lg-6" >
<label for="select-from">Select SubCategory:<span class="required" style="color:red;">*</span></label>
<select name="submenu_id" id="submenu" class="form-control">
<option value="">Choose</option>
</select>
</div>
<div class="form-group col-lg-12">
<label for="category">Product Name <span class="required" style="color:red;">*</span> </label>
<div>
<input type="text" name="name" required class="form-control">
</div>
</div>
<div class="form-group col-lg-6">
<label for="category">Image <span class="required" style="color:red;">*</span> </label>
<div>
<input type="file" name="image" required class="form-control">
</div>
</div>
<div class="form-group col-lg-12">
<label for="category">Old Price <span class="required" style="color:red;">*</span> </label>
<div>
<input type="text" name="old_price" required class="form-control">
</div>
</div>
<div class="form-group col-lg-12">
<label for="category">New Price <span class="required" style="color:red;">*</span> </label>
<div>
<input type="text" name="new_price" required class="form-control">
</div>
</div>
<script src="{{URL::to('ckeditorfull/ckeditor/ckeditor.js')}}"></script>
<div class="form-group col-lg-12">
<label for="category">Detail <span class="required" style="color:red;">*</span> </label>
<div>
<textarea class="form-control" id="detail" name="detail" ></textarea>
</div>
</div>
<script>
CKEDITOR.replace( 'detail');
</script>
<div class="ln_solid"></div>
<div class="form-group ">
<div>
<button type="submit" class="btn btn-success pull-right" style="background: #1abb9c;">Submit</button>
</div>
</div>
below is controller
public function add_action(Request $request){
//dd($request->all());
$datas=new Product();
$this->validate($request,['name'=>'required|unique:products',
'image'=>'required',
'old_price'=>'required',
'new_price'=>'required',
'detail'=>'required',
'total_products'=>'required',
'size'=>'required',
'total_sizeproducts'=>'required']);
$datas->category_id=$request->category;
$datas->menu_id=$request->submenu_id;
$datas->name=$request->name;
$datas->slug=str_slug($request->name);
if($request->hasFile('image')){
$file=$request->file('image');
$filename=time().$file->getClientOriginalName();
$file->move(public_path().'/backend/images/products/',$filename);
$datas->image=$filename;
}
$datas->new_price=$request->new_price;
$datas->old_price=$request->old_price;
$datas->rating=$request->rating;
$datas->brand=$request->brand;
$datas->availability=$request->availability;
$datas->total_products=$request->total_products;
$datas->discount=$request->discount;
$datas->detail=$request->detail;
$datas->save();
}
return redirect()->back()->with('success','products added successfully!!!');
}
below is route
Route::group(['namespace'=>'product','prefix'=>'product','middleware'=>'auth'],function (){
Route::get('/','ProductController#add')->name('product');
Route::post('/','ProductController#add_action');
});
Post some code. But you can use dd($request) and you will be able to see the data thats being sent to the controller. Make sure you are using the correct route for that action.

Laravel Dynamic Form Submit not responding

I have a controller ( Laravel ) which will be dynamic create a form as below
<div class="row" style="margin-bottom:30px;margin-top:20px;">
<div class="col-2">
<form class="addform" id="newcheckform" role="form">
'.csrf_field().'
<label class="" for="cust_code">Cust Code</label>
<input type="text" class="form-control" id="cust_code" value="'.$row->cust_no.'">
</div>
<div class="col-2">
<label class="" for="cust_short">Cust Shortname</label>
<input type="text" class="form-control" id="cust_short">
</div>
<div class="col-4">
<label class="" for="cust_name">Cust Name</label>
<input type="text" class="form-control" id="cust_name" value="'.$row->cust.'">
</div>
<div class="col-2">
<label class="" for="region">Region</label>
<input type="text" class="form-control" id="region">
</div>
<div class="col-2">
<label class="" for="region">Add Cust Data</label>
<button class="btn btn-sm btn-info" id="createnewcust" type="submit">Create</button>
</form>
</div>
</div>
if will be loaded by below script in the blade file
$("#custcheck").load("{{ url('/sales/admin/custcheck') }}");
The form displayed as its should to be.
However I when I submit button. Nothing happened. code as below. Appreciate anyone can help. this script resides in the same blade file.
$(function() {
$(document).on('submit', '#newcheckform', function(e){
alert("Hi");
});
});
You have wrong closing tags for <form> change something like this:
<div class="row" style="margin-bottom:30px;margin-top:20px;">
<form class="addform" id="newcheckform" role="form">
{{csrf_field()}}
<div class="col-2">
<label class="" for="cust_code">Cust Code</label>
<input type="text" class="form-control" id="cust_code" value="{{$row->cust_no}}">
</div>
<div class="col-2">
<label class="" for="cust_short">Cust Shortname</label>
<input type="text" class="form-control" id="cust_short">
</div>
<div class="col-4">
<label class="" for="cust_name">Cust Name</label>
<input type="text" class="form-control" id="cust_name" value="{{$row->cust}}">
</div>
<div class="col-2">
<label class="" for="region">Region</label>
<input type="text" class="form-control" id="region">
</div>
<div class="col-2">
<label class="" for="region">Add Cust Data</label>
<button class="btn btn-sm btn-info" id="createnewcust" type="submit">Create</button>
</div>
</form>
</div>
This will work.

Resources