When I try to update my lead_status it's not updating it's only redirecting to a page but can't update my lead status and when I return or dd($leads) it gives 0. why let me where I'm wrong and suggest me a solution
my update query
public function leadUpdate(Request $request)
{
$ids = $request->ids;
$lead_status = $request->lead_status;
$leads = DB::table('leads')
->where('id', $ids)
->update(['lead_status' => $lead_status]);
dd($leads);
return redirect('home/progress-leads')->with('success', 'lead accepted successfully');
}
my route is
Route::put('/home/accept-leads','HomeController#leadUpdate');
my blade form is
<form action="{{ url('home/accept-leads') }}" method="POST">
#csrf
#method('PUT')
<!-- Modal Header -->
<div class="modal-header">
<h4 class="modal-title">Accept Leads</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<div class="row">
<div class="col-xs-6 col-sm-6 col-md-12">
<h3>Are you sure to accept this lead</h3>
<div class="form-group">
<input type="checkbox" name="ids" value="{{ $leads->id }}">
<input type="hidden" class="form-control" name="lead_status">
</div>
</div>
</div>
</div>
<!-- Modal footer -->
<div class="modal-footer">
<button formaction="/home/accept-leads" type="submit" onclick="return myConfirm();" class="btn btn-primary">Submit</button>
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</form>
Please help me...
Thanks in advance
Related
I have created a form for Making Category and on the same page I am displaying the categories in form of tables. In front of each category there is a Add button to add subcategory. I want to display a modal which has a form for subcategory .
I am not able to add subcategory. When I click submit the submitted details are displayed in raw form and it is selecting only Id 1 everytime
Controller:
public function subcat(Request $request, $id)
{
$data = new SubCategories();
$data->name = $request->input('name');
$data->categories_id=$id;
if($request->hasfile('image')){
$file = $request->file('image');
$extension = $file->getClientOriginalExtension();
$filename = time().'.'.$extension;
$file->move('uploads/subcategory/',$filename);
$data->image = $filename;
}else{
return $request;
$data->image = '';
}
$data->save();
return redirect('/admin/addCategory')->with('Success', 'SubCategory Added');
}
Blade
#extends('admin.master');
#section('content');
<div class="content-wrapper">
<div class="row">
<div class="container">
<form action="{{route('store')}}" method="POST">
{{csrf_field()}}
<label for="cat_name">Category Name</label>
<input type="text" name="cat_name" class="form-control">
<button type="submit" class="btn btn-success">Submit</button>
</form>
</div>
</div>
<div class="row">
<div class="container">
<table class="table table-dark">
<tr>
<thead>
<th>ID</th>
<th>Category</th>
<th>AddSubCategory</th>
</thead>
</tr>
<tbody>
#foreach($category as $col)
<tr>
<td>{{$col->id}}</td>
<td>{{$col->cat_name}}</td>
<td><a class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" href="/admin/category/{{$col->id}}">Add</a></td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add SubCategory</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="{{route('storeSub',[$category[0]->id])}}" method="POST">
{{csrf_field()}}
<label for="name">SubCategory</label>
<input type="text" name="name" class="form-control">
<label for="image">Image</label>
<input type="file" name="image" class="form-control">
<button type="submit" class="btn btn-primary">Save changes</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
#endsection
Route
Route::prefix('/admin')->group( function() {
Route::get('/addCategory','\App\Http\Controllers\AdminController#index');
Route::post('/storecat','\App\Http\Controllers\AdminController#categories')->name('store');
Route::get('/addCategory','\App\Http\Controllers\AdminController#show');
Route::post('/category/{id}','\App\Http\Controllers\AdminController#subcat')->name('storeSub');
});
Your probably not summiting a file, so the else statement is the path you are on. Because of this line
else{
return $request; // Remove This
...
Everything stops at that point and you are returning the raw form request data which Laravel is automatically turning into JSON. You'll need to remove that line in order for the rest of your method to continue processing.
Because your modal is out of the foreach.
action="{{route('storeSub',[$category[0]->id])}}" on modal form can't handle above table's values.
Try to move modal area to foreach or, change modal's values with javascript dynamically.
The reason why everytime getting category id = 1 is, Because you're submitting on modal form action like
$category[0]->id
This means every time send category id = 1
So solutions is should be near to this in your blade file;
#extends('admin.master');
#section('content');
<div class="content-wrapper">
<div class="row">
<div class="container">
<form action="{{route('store')}}" method="POST">
{{csrf_field()}}
<label for="cat_name">Category Name</label>
<input type="text" name="cat_name" class="form-control">
<button type="submit" class="btn btn-success">Submit</button>
</form>
</div>
</div>
<div class="row">
<div class="container">
<table class="table table-dark">
<tr>
<thead>
<th>ID</th>
<th>Category</th>
<th>AddSubCategory</th>
</thead>
</tr>
<tbody>
#foreach($category as $col)
<tr>
<td>{{$col->id}}</td>
<td>{{$col->cat_name}}</td>
<td><a class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" href="/admin/category/{{$col->id}}">Add</a></td>
</tr>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add SubCategory</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="{{route('storeSub',[$col->id])}}" method="POST">
{{csrf_field()}}
<label for="name">SubCategory</label>
<input type="text" name="name" class="form-control">
<label for="image">Image</label>
<input type="file" name="image" class="form-control">
<button type="submit" class="btn btn-primary">Save changes</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
</div>
#endsection
May be the problem is in your javascript file that operate the modal class. Please provide more information on the related script.
While submitting a form on a pop-up modal the page gets expired on laravel, I am sending a post request.
Can someone please help? i have added a csrf token too..
View Blade
<div id="reviewModal-{{$ecgparticipant->getoriginal()['id']}}" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header" >
</div>
<div class="modal-body">
<form id="ecgreviewform" class="ecgreview" action="{{ route('ecg.reviewstore') }}" method="POST">
#csrf
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="tesdt" id="exampleInputEmail1" aria-describedby="emailHelp" value="{{auth()->user()->name}}">
</div>
</div>
<div class="modal-footer">
<div class="row">
<div class="col-md-6">
<button type="button" style = "width:50%;" class="btn btn-primary btn-outline-blue btn-close-modal" data-dismiss="modal">Cancel</button>
</div>
<input type="hidden" name="participant_id" value="{{$ecgparticipant->getoriginal()['id']}}">
<div class="col-md-6">
</div>
</div>
<button type="submit" form="ecgreviewform" style = "width:50%;" name="submit" value="submit" class="btn btn-primary">Save</button>
</div>
</form>
</div>
</div>
</div>
</div>
Route page
Route::get('ecg/pendingreview', 'EcgReviewController#index')->name('ecg.pendingreview');
Route::post('ecg/pendingreview', 'EcgReviewController#store')->name('ecg.reviewstore');
is there any reason
assign in your form 'method' like this:
<form method="post">
#csrf <!-- {{ csrf_field() }} -->
</form>
try with
{{ csrf_field() }}
I'm having an issue getting data to transfer into my delete confirmation modal.
I've verified my delete route works in removing data from the data base but the issue I'm facing is that I can't pass the contact->id into the modal to access for deletion.
The Modal
<!-- Delete Warning Modal -->
<div class="modal modal-danger fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="Delete" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Delete Contact</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="{{ route('contacts.destroy', 'id') }}" method="post">
#csrf
#method('DELETE')
<input id="id" name="id")>
<h5 class="text-center">Are you sure you want to delete this contact?</h5>
<input id="firstName" name="firstName"><input id="lastName" name="lastName">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-sm btn-danger">Yes, Delete Contact</button>
</div>
</form>
</div>
</div>
</div>
<!-- End Delete Modal -->
Blade call
<td>
<a href="#"
data-id={{$value->id}}
class="btn btn-danger delete"
data-toggle="modal"
data-target="#deleteModal">Delete</a>
</td>
Contact Controller
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
// Need to find all addresses with the contacdt Id and delete them.
Address::where('contact_id', $id)->delete();
Contact::find($id)->delete();
return redirect()->route('contacts.index')->with('success','Contact deleted success');
}
To summarize, my issue is getting jQuery to transfer data to the modal so I can then use it to delete the data... right now my id=null
Jquery code:
$(document).on('click','.delete',function(){
let id = $(this).attr('data-id');
$('#id').val(id);
});
Also in your modal html code:
<input id="id" name="id">
In your bootstrap modal form change the following:
<form action="{{ route('contacts.destroy', 'id') }}" method="post">
#csrf
#method('DELETE')
<input id="id" name="id" hidden>
<h5 class="text-center">Are you sure you want to delete this contact?</h5>
<input id="firstName" name="firstName"><input id="lastName" name="lastName">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-sm btn-danger">Yes, Delete Contact</button>
</div>
</form>
In the above code you are passing the string parameter that is 'id' to the controller so it will detect 'id' which is string you need to bring little bit changes in your controller as well instead of taking 'id' directly as parameter you need to take the request as you are placing the selected id into the input field that is :
<input id="id" name="id" hidden value="">
Add the jquery:
<script>
$(document).on('click','.delete',function(){
let id = $(this).attr('data-id');
$('#id').val(id);
});
</script>
Controller should be:
public function destroy(Request $request)
{
$id= $request->id;
$items = yourModel::find($id);
$items->delete();
return redirect()->route('your page')->with('message', 'report details has been successfully deleted');
}
<div class="table-responsive">
<table class="table table-bordered table-sm">
<thead>
<tr>
<th>ID</th>
<th>Nombre</th>
<th>Usuario</th>
<th>Acción</th>
</tr>
</thead>
#foreach($users as $user)
<tbody>
<tr>
<td>{{ $user->id }}</td>
<td>{{ $user->nombre }}</td>
<td>{{ $user->login}}</td>
<td>
<i class="bi bi-pencil-square"></i>
<a data-bs-toggle="modal" class="btn btn-warning" data-bs-target="#deleteUserModal_{{$user->id}}"
data-action="{{ route('users.destroy', $user->id) }}"><i class="bi bi-trash"></i></a>
</td>
</tr>
</tbody>
<!-- Delete User Modal -->
<div class="modal fade" id="deleteUserModal_{{$user->id}}" data-backdrop="static" tabindex="-1" role="dialog"
aria-labelledby="deleteUserModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteUserModalLabel">Esta acción es irreversible.</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<form action="{{ route('users.destroy', $user->id) }}">
<div class="modal-body">
#csrf
#method('DELETE')
<h5 class="text-center">¿Estás seguro de que quieres eliminar al usuario
{{ $user->nombre }} {{ $user->apellido_materno }} {{ $user->apellido_paterno }} ?</h5>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
<button type="submit" class="btn btn-danger">Si, Eliminar Usuario</button>
</div>
</form>
</div>
</div>
</div>
#endforeach
</table>
</div>
I am trying to send the data to the backend on a new front-end, the backend is working to display the bootstrap modal except the front end display is previewing this error. It is successfully adding but without retrieving the validation set from the js file.
Uncaught TypeError: $(...).DataTable is not a function
at HTMLDocument.<anonymous> (customers.js:8)
from
manageCustomerTable = $("#manageCustomerTable").DataTable({
'ajax': 'php_action/fetchCustomers.php',
'order': []
});
I am a newbie to programming, all I want to do is sign-up the customer to send the details to the backend successfully from the new front-end view for the customer.
<?php
require_once 'php_action/db_connect.php';
?>
<?php require_once 'php_action/core.php'; ?>
<?php require_once 'includes/header.php'; ?>
<table class="table" id="manageCustomerTable">
</table>
<form class="form-horizontal" id="submitCustomerForm" action="php_action/createCustomers.php" method="POST">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title"><i class="fa fa-plus"></i> Add Beautician</h4>
</div>
<div class="modal-body">
<div id="add-customer-messages"></div>
<div class="form-group">
<label for="c_Title" class="col-sm-3 control-label">Title: </label>
<label class="col-sm-1 control-label">: </label>
<div class="col-sm-8">
<input type="text" class="form-control" id="c_Title" placeholder="Title Name" name="c_Title" autocomplete="off">
</div>
</div> <!-- /form-group-->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary" id="createCustomerBtn" data-loading-text="Loading..." autocomplete="off">Save Changes</button>
</div>
<!-- /modal-footer -->
</form>
<!-- /.form -->
<script src="custom/js/customers.js"></script>
Tomorrow I am presenting my code in sprint. Everything was working fine until a few hours ago. I have a modal which pops up when a user clicks on Edit. It was giving the values according to id.
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
#foreach($Community as $editCommunity)
<h4 class="modal-title">Edit: {!! $editCommunity->community_name !!}</h4>
</div>
<div class="modal-body">
<form class="form-group" action="/update/{{$editCommunity->id}}" method="post" id="editCommunityForm">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="text" name="community_name" class="form-control" value="{{$editCommunity->community_name}}">
</form>
#endforeach
<button class="btn btn-custom dropdown-toggle waves-effect waves-light" type="submit" form="editCommunityForm">Update Community</button><br /><br />
</div>
<div class="modal-footer">
{{--<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>--}}
</div>
</div>
</div>
</div>
I am very upset and confused and don't know what to do.
Any help would highly be appreciated
Edit:
After reading the comments; i have understood that only one id would be updated every time. How could i change the id dynamically and update data of that specific id and each time it should get only clicked id.
Controller Function to update:
public function updateCommunity($id, CommunityRequest $request) {
$updateCommunity = Community::findOrFail($id);
$updateCommunity->update($request->all());
return back();
}
View Buttons:
#foreach ($Community as $communities)
<tr>
<td>{{$communities->community_name}}</td>
<td> <button type="button" class="btn btn-primary dropdown-toggle waves-effect waves-light" data-toggle="modal" data-target="#myModal">Edit</button>
| Delete</td>
</tr>
#endforeach
Update
I understand you have all the communities listed in a list somewhere outside this modal, each entry has an edit and delete button. Upon clicking edit button user should be presented a modal with a single form to edit community he clicked that button for. All this using a single modal element.
The fact that you don't want to use more than one modal means you want to generate less DOM in order to provide faster loading times, if that's the case then edit your view buttons.
#foreach ($Community as $communities)
<tr>
<td>{{$communities->community_name}}</td>
<td> <button type="button" class="btn btn-primary dropdown-toggle waves-effect waves-light" data-toggle="modal" data-target="#myModal" data-community="{{ json_encode($communities) }}">Edit</button>
| Delete</td>
</tr>
#endforeach
Notice new data-community attribute in edit button.
Now change your modal to provide a template for community edit form instead of providing a form for each community.
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Edit: <span></span></h4>
</div>
<div class="modal-body">
<form class="form-group" method="post" id="editCommunityForm">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="text" name="community_name" class="form-control">
</form>
<button class="btn btn-custom dropdown-toggle waves-effect waves-light" type="submit" form="editCommunityForm">Update Community</button><br /><br />
</div>
<div class="modal-footer">
{{--<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>--}}
</div>
</div>
</div>
</div>
Now what you need to do it listen to edit community button click event (the one from view buttons), get data-community object from it, open a modal and fill with to fit edited community.
search for $('modal-title span') and .html() community name into it
search for $('#editCommunityForm') and change it's action to \update\{community_id}
search for $('button[form="editCommunityForm"]) and on click send form using ajax
There are many other ways to do this, better ways, it's just a simple example on how you can make it work.
Original answer
How come your submit button is outside of foreach but in an image it is displayed after each form? Also you are closing <div> tag in a loop that you opened before that loop.
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
#foreach($Community as $editCommunity)
<h4 class="modal-title">Edit: {!! $editCommunity->community_name !!}</h4>
</div> // You are closing a tag opened before foreach loop
<div class="modal-body">
<form class="form-group" action="/update/{{$editCommunity->id}}" method="post" id="editCommunityForm">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="text" name="community_name" class="form-control" value="{{$editCommunity->community_name}}">
</form>
#endforeach
<button class="btn btn-custom dropdown-toggle waves-effect waves-light" type="submit" form="editCommunityForm">Update Community</button><br /><br />
</div>
After you fix this you can simply edit form id by adding $editCommunity->id to it, like so:
<form class="form-group" action="/update/{{$editCommunity->id}}" method="post" id="editCommunityForm_{{$editCommunity->id}}">
Then you can edit button's form parameter to match your form:
<button class="btn btn-custom dropdown-toggle waves-effect waves-light" type="submit" form="editCommunityForm_{{$editCommunity->id}}">Update Community</button>
You should end up with this:
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
#foreach($Community as $editCommunity)
<h4 class="modal-title">Edit: {!! $editCommunity->community_name !!}</h4>
<form class="form-group" action="/update/{{$editCommunity->id}}" method="post" id="editCommunityForm_{{$editCommunity->id}}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="text" name="community_name" class="form-control" value="{{$editCommunity->community_name}}">
</form>
<button class="btn btn-custom dropdown-toggle waves-effect waves-light" type="submit" form="editCommunityForm_{{$editCommunity->id}}">Update Community</button><br /><br />
#endforeach
</div>
<div class="modal-footer">
{{--<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>--}}
</div>
</div>
</div>
</div>