« first day (41 days earlier)      last day (307 days later) » 

9:40 AM
@ZakariaAcharki Hi sir
Whatever checkboxes I selected but I only see the first checkbox in the console
Even If I am not selecting the first one
Then it also shows me the first one
 
 
1 hour later…
11:05 AM
Then use this code instead :

var checkBoxArray = [];
$('[name="checkBoxArray[]"]:checked').each(function(){ checkBoxArray.push($(this).val()); })
console.log( checkBoxArray );
 
ok sir
0: "3"

1: "4"

length: 2
@ZakariaAcharki
Yes sir I am getting the right data now
 
11:24 AM
good job now
we need to send it to the controller
so in your data object add
checkBoxArray: checkBoxArray
side by side with the _method and _token
 
"id": id,
"_method": 'DELETE',
"_token": token,
"checkBoxArray": checkBoxArray,
Like this ?
 
no need for the id
it's already passed in the route
 
ok
I was about to remove it
What's next sir ?
 
11:44 AM
show me the controller action
what do you get from the dd
 
array:2 [▼
"_method" => "DELETE"
"_token" => "bQydJWLlsBRd92Xe3gQzDFd7bePOHSRmSdm1QFdD"
]
I am still getting this from the dd
 
12:18 PM
show me the whole Js function
and the whole controller action please
 
ok
$(".deleteInvoice").click(function(){
var id = $(this).data("id");
var token = $('[name="csrf-token"]').attr('content');
var checkBoxArray = [];
$('[name="checkBoxArray[]"]:checked').each(function(){ checkBoxArray.push($(this).val()); });
console.log( checkBoxArray );
$.ajax(
{
url: "invoice/delete/"+id,
type: 'PATCH',
dataType: "JSON",
data: {
"_method": 'DELETE',
"_token": token,
"checkBoxArray": checkBoxArray,
},
});

});
public function destroy(Request $request)
{


dd($request->all());

}
 
replace :
console.log( checkBoxArray );

By :

console.log({"_method": 'DELETE', "_token": token, "checkBoxArray": checkBoxArray});
 
ok sir but let me tell you another thing
When I click the delete button then I can see the 404 PATCH undefined request in the network tab
After doing that. Still seeing the same array sir
 
take a screenshot of the 404
and send it to me please
 
ok I will you email you that now
I sent you
Check it out please
 
1:16 PM
Hi
Show me the routes too please, and try to use post instead of patch in both route & ajax
 
2:08 PM
ok sir
Sorry for the late reply
Route::post('invoice/delete/{id}', 'UserController@destroy');
@ZakariaAcharki
This is the route I changed it to post from patch and in the ajax too
But still facing the same 404 request
Route::post('/invoice/delete/{id}', 'UserController@destroy');
I also tried like this but not working
 
change the url in the ajax request to ( url: "/invoice/delete/"+id, )
note the "/" at the start
 
yeah I did that too while ago
But still not working
 
it must work
and to avoid the undefined in the url
 
now its going 405
request
 
why you're not using my version where I get the action with the if from the form action attribute like

var action = $(this).prop("action");
...
$.ajax(
{
url: action,
...
var action = "/"+$(this).prop("action");
add the slash
and try again
 
2:23 PM
ok
let me use that one
 
the 404 error can't resolve the url because of the /admin at the beginning
 
var status = $(this).val();
if (status) {
Like this right ?
 
if we use "/" it will work
 
Yeah I used "/" and now its giving the 405
 
good
is there any error message
 
2:24 PM
yeah its the 405 undefined POST
And in the header it has line says
Method not allowed
 
show me the whole JS code
 
okay
 
the relevant part I mean
 
$(".deleteInvoice").click(function(){
var id = $(this).data("id");
var token = $('[name="csrf-token"]').attr('content');
var checkBoxArray = [];
$('[name="checkBoxArray[]"]:checked').each(function(){ checkBoxArray.push($(this).val()); });
console.log({"_method": 'DELETE', "_token": token, "checkBoxArray": checkBoxArray});
$.ajax(
{
url: "/invoice/delete/"+id,
type: 'POST',
dataType: "JSON",
data: {
"_method": 'DELETE',
"_token": token,
"checkBoxArray": checkBoxArray,
},
});

});
 
ok
try it like this
$(".deleteInvoice").click(function(){
var action = "/"+$(this).prop("action");
alert( action );
var token = $('[name="csrf-token"]').attr('content');
var checkBoxArray = [];

$('[name="checkBoxArray[]"]:checked').each(function(){ checkBoxArray.push($(this).val()); });
$.ajax(
{
url: action,
type: 'POST',
dataType: "JSON",
data: {
"_method": 'DELETE',
"_token": token,
"checkBoxArray": checkBoxArray,
},
});

});
 
2:27 PM
ok
 
with this route Route::post('invoice/delete/{id}', 'UserController@destroy');
 
okay
give me some mins
 
and let me know what is the result in the alert box
take your time
 
ok
when I submit it
First i see the alert
saying undefined
Then the 404 error again in the network tab
 
2:32 PM
okay
 
var action = "/"+$(this).closest('form').prop("action");
try this instead
and check the alert again
 
then show me the form
of the delete
 
{!! Form::open(['method'=>'GET', 'action'=>'FeeController@invoicesActions']) !!}

<div class="form-group">
<a data-toggle="modal" data-target="#deleteInvoiceModal">
<button class="deleteInvoice btn btn-danger float-right fas fa-trash-alt"> Delete</button>
</a>
</div>
Its not the whole form
You can see from the a tag i am going to the modal
Let me show you the modal too
@foreach($invoices as $invoice)
<div class="modal fade" id="deleteInvoiceModal">
<div class="modal-dialog modal-md">
<div class="modal-content">

<div class="modal-header bg-danger text-white">
<h5 class="modal-title">Delete Confirmation</h5>
<button class="close" data-dismiss="modal">
<span class="text-white">&times;</span>
</button>
</div>
<div class="container">
<div class="modal-body">
<div class="col-md-12">
<p class="text-center">Do you really want to delete ?</p>
{!! Form::model($invoice, ['method'=>'DELETE', 'action'=>['FeeController@destroy', $invoice->id]]) !!}
 
this is not what you show me the last time
it was something like
{!! Form::model($invoice, ['method'=>'DELETE', 'action'=>['FeeController@destroy', $invoice->id]]) !!}
aaah
I think now the invoice ids are the values from the checkboxes?
is that right ?
 
2:37 PM
Yeah that's the modal
haha I am laughing at my code. I am confusing you :(
yes
exactly
 
ya
wait
then the route must not contain the id
it must be like with this route Route::post('invoice/delete', 'UserController@destroy');
 
ok
okay
then ?
 
then ajax part
$.ajax(
{
url: "/invoice/delete",
type: 'POST',
dataType: "JSON",
data: {
"_method": 'DELETE',
"_token": token,
"checkBoxArray": checkBoxArray,
},
});
 
okay
 
ctrl+f5
and try
 
2:39 PM
okay
Going to this
And then 403 request
$(".deleteInvoice").click(function(){
var action = "/"+$(this).closest('form').prop("action");
alert( action );
var token = $('[name="csrf-token"]').attr('content');
var checkBoxArray = [];

$('[name="checkBoxArray[]"]:checked').each(function(){ checkBoxArray.push($(this).val()); });
$.ajax(
{
url: action,
type: 'POST',
dataType: "JSON",
data: {
"_method": 'DELETE',
"_token": token,
"checkBoxArray": checkBoxArray,
},
});

});
this is the ajax
 
you're not using the last ajax I sent you
replace it
check the url
is not the same
 
yeah replace it now
Sorry
recieving this alert
and 404 post request again
And in the alert after clicking the delete again then its giving me the same array from dd
array:2 [▼
"_method" => "DELETE"
"_token" => "bQydJWLlsBRd92Xe3gQzDFd7bePOHSRmSdm1QFdD"
]
 
<button type="button" class="deleteInvoice btn btn-danger float-right fas fa-trash-alt"> Delete</button>
Replace your button
 
ok
404 request again
:(
 
remove the alert
 
2:48 PM
ok
 
and show me the url you get in the network tab
 
ok
Its from the 404 request
 
even if you do $.ajax(
{
url: "/invoice/delete",
type: 'POST',
??
with the slash at the start
 
yes
$.ajax(
{
url: "/invoice/delete",
type: 'POST',
 
where is the / :D
yes
try it
like this
 
2:51 PM
Yeah with that it also giving me the 404 request
That's why I removed that "/" and look if it works without that
but both ways not working
:(
 
it must work with it
have you cleared the cache ?
 
Route::post('invoice/delete}', 'FeeController@destroy');
This is the route
Yeah i did
 
try it with the / too
at the start
 
Yeah also tried with that too
haha don't know where is the bug
 
I need really to see the 404 route
you will find it in this position
 
2:57 PM
let me check it
See
Exactly from the same position i copied it
 
try to remove the "_method": "DELETE"
part from the data object
 
if it's not working
send me a new screenshot
 
I am sending you the new screenshot
check that out
 
3:22 PM
I am waiting here. When you are done then text me
:)
 
4:21 PM
Route::any('invoice/delete}', 'FeeController@destroy');
Route::any('/invoice/delete}', 'FeeController@destroy');
wait
 
okay sir
 
Route::any('invoice/delete', 'FeeController@destroy');
 
okay
 
just this one
 
okay sir
And remove the my own route ?
 
4:22 PM
yes
 
ok
yes:)
Now I am not getting that error
But from the dd I am getting the same array
 
haha
replace it with
Route::post('invoice/delete', 'FeeController@destroy');
must work too
 
okay
haha
magic
:D
Yeah its working now
Can you explain this logic please ? :D
 
hhhh
there's no logic
we're both tired I think that why
 
haha yeah exactly I was also thinking the same :D
 
4:25 PM
it was a long week
it was just a "}"
after the delete that must be removed
just a typo
 
hahaha OMG
Hit me hard now :D
 
now from the dd I am getting this array
array:2 [▼
"_method" => "DELETE"
"_token" => "bQydJWLlsBRd92Xe3gQzDFd7bePOHSRmSdm1QFdD"
]
 
we already removed _method ?
 
4:30 PM
show me the last version of the js function
 
$(".deleteInvoice").click(function(){
var token = $('[name="csrf-token"]').attr('content');
var checkBoxArray = [];

$('[name="checkBoxArray[]"]:checked').each(function(){ checkBoxArray.push($(this).val()); });
$.ajax(
{
url: "/invoice/delete",
type: 'POST',
dataType: "JSON",
data: {
"_token": token,
"checkBoxArray": checkBoxArray,
},
});

});
 
have tried again
because we sent no _method
 
yeah
But why in the array I have that _method again
 
not sure
 
4:51 PM
okay sir
Find out
array:2 [
"_token" => "bQydJWLlsBRd92Xe3gQzDFd7bePOHSRmSdm1QFdD"
"checkBoxArray" => array:1 [
0 => "3"
]
]
that dd not giving me these checboxes
But the 200 request response in the network tab is giving me
Finally worked also :D
public function destroy(Request $request)
{
if (!empty($request->checkBoxArray)) {
Fee::whereIn('id', $request->checkBoxArray)->delete();
return response()->json();
}
return redirect()->back();
}
With this controller
Thank you so much sir for your time and support. Allah bless you. :)
Now I am going to start the new section. When you have time then text me here because I need to discuss something in that section with you. And this is the hardest section for me that's why I leave it for the last. I already set routes and everything but before starting deeply I need to discuss that
I will wait for you :)
See you soon insha'Allah :)
 
5:27 PM
inshallah
You're welcome, glad to help
 

« first day (41 days earlier)      last day (307 days later) »