Laravel 5.4 CRUD DELETE Method not working, there is no reaction on clicking DELETE - laravel

After clicking on DELETE, there is no reaction, absolutely nothing happens. I am using HTML Forms, that's why I used, #method('DELETE'). I had similar problem with edit, after using #method(PUT), edit is working properly.
<div class="row">
<div class="col-6 align-self-start">
<a class="btn btn-light" href="/listings/{{$listing->id}}/edit">Edit</a>
</div>
<div class="col-6 align-self-end">
<form action="{{action('ListingsController#destroy', [$listing->id])}}" method="POST">
<?= csrf_field()?>
#method('DELETE')
<a class="btn btn-danger" href="/dashboard">Delete</a>
</form>
</div>
</div>
Destroy Function:
public function destroy($id)
{
$listing = Listing::find($id);
$listing->delete();
return redirect('/dashboard')->with('success', 'Contact Deleted');
}

Change
<a class="btn btn-danger" href="/dashboard">Delete</a>
to
<a type="submit" class="btn btn-danger" href="/dashboard">Delete</a>
You should add submit otherwise it will not submit the form.

Its recommended to use a instead of :
<button type="submit" class="btn btn-danger">Delete</button>

Related

How to show data from database inside textarea

Is it possible to show data with button modal datatable from database inside textarea? My case is, the button modal inside datatable area, and when I click the button it appears modal and data inside textarea. This is my code :
->addColumn('detail', function ($data) {
$html = '
<div class="d-flex justify-content-center">
<button class="btn btn-light-success mx-2 btn-sm detail" '. $data->id .' ">
<i class="fa fa-search"></i>
Detail
</button>
</div>
';
return $html;
})
And this is a view :
<form action="{{route('accelerate-setting.submit_comment')}}" method="POST" class="load-form" enctype="multipart/form-data">
#csrf
<input type="hidden" name="id" value="">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Detail Comment</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i aria-hidden="true" class="ki ki-close"></i>
</button>
</div>
<div class="modal-body">
<div class="form-group">
<textarea class="form form-control" name="detail_comment" rows="6" disabled></textarea>
</div>
<button type="submit" name="action" class="btn btn-primary font-weight-bold btn-block" value="submit">Submit</button>
</div>
Thanks, hope u understand what my case is. I'm really confusing!

Submit Button not getting correct route to add new data in Laravel

I am facing problem for Submit Button not getting correct route to add new data.
2 Blade file with 2 Submit Button which need to save 2 data to 2 different tables.
Problem facing - Data submitted in 1 table for both submit button....
addnewBuffalo.blade.php
<div class="box-header with-border" align="right">
<button type="submit" class="btn btn-success btn"><i class="fa fa-floppy-o"></i> <b>Add
Buffalo</b></button><a href="" class="btn btn-warning btn"><i class="fa fa-refresh">
</i> <b> Refresh</b></a>
</div>
addnewcow.blade.php
<div class="box-header with-border" align="right">
<button type="submit" class="btn btn-success btn"><i class="fa fa-floppy-o"></i> <b>Add
Cow</b></button><a href="" class="btn btn-warning btn"><i class="fa fa-refresh"></i> <b>
Refresh</b></a>
</div>
web.php
Route:: post('submit', 'App\Http\Controllers\addnewbuffaloController#addbuffaloData')
->name('submit');
Route:: post('submit', 'App\Http\Controllers\addnewcowController#addcowData')
->name('submit');
You need to create 2 separate Route Names. Having ->name('submit') for both won't work. And having the same path won't work
Route::post('submit=buffalo', 'App\Http\Controllers\addnewbuffaloController#addbuffaloData')
->name('submit-buffalo');
Route::post('submit-cow', 'App\Http\Controllers\addnewcowController#addcowData')
->name('submit-cow');
Or if the form is wrapped by one form tag then you can handle both submissions in the one Controller action
<button type="submit" name="buffalo-submission">Save Buffalo</button>
<button type="submit" name="cow-submission">Save Cow</button>
Then in the controller action code you could check
if ($request->has('buffalo-submission') {
Do buffalo code
} else if ($request->has('cow-submission')) {
do cow code
}

why my database does not update ? (LARAVEL)

my database does not update while when i do
dd(request()->has('validated'));
this is what my web.php looks like:
Route::patch('prof/theme/{id}/validated', 'Theme\ThemeController#valide')->name('prof.theme.validated');
this is what my ThemeController.php looks like:
public function valide(Theme $theme) {
$theme->update([
'validated' => request()->has('validated')
]);
return back();
}
this is what my show.blade.php looks like:
<form action="{{route('prof.theme.validated', $theme)}}" method="POST">
#csrf
#method('PATCH')
#if ($theme->validated)
<button type="submit" class="btn btn-danger text-center" style="width: 350px">
INVALIDER LE THEME
</button>
#else
<button type="submit" class="btn btn-success text-center" name="validated" id="validated" style="width: 350px">
VALIDER LE THEME
</button>
#endif
</form>
this code does not show me any error but it does not produce the expected action. my variable "validated" is a boolean
thank you Harshith VA!!!!! i was able to solve the problem thanks to your idea. I kept your view and used your controller idea this way
public function valide(Request $request, Theme $theme) {
$theme->validated = $request->has('validated');
$theme->save();
return back();
}
thanks you for your help
From first look, I would believe this is due to the fact that you have added name="validated" to the <button> and not as an <input>.
<form action="{{route('prof.theme.validated', $theme)}}" method="POST">
#csrf
#method('PATCH')
#if ($theme->validated)
<button type="submit" class="btn btn-danger text-center" style="width: 350px">
INVALIDER LE THEME
</button>
#else
<input type="hidden" name="validated" value="true">
<button type="submit" class="btn btn-success text-center" style="width: 350px">
VALIDER LE THEME
</button>
#endif
</form>
Here, we add a hidden input field with the validated input. Doing this should pass that the validated key/value to the controller.
Another point. dd() is used to die and dump data, and would stop execution of whatever script is running. Therefore it won't save to the db once you do this.
The above assumes you didn't mean it doesn't save to the database when you dd().
Update
Also note that ->has() checks if the input exists. You should use request('validated') to get its value.

Laravel 5.2 - Form do not submit

Sorry, i'm very new to Laravel, i have this form:
<form action="/register" method="post">
{!! csrf_field() !!}
....
<div class="form-group">
<button type="button" class="btn btn-default">Register</button>
</div>
</form>
And the route is:
Route::get('/register', 'Auth\AuthController#getRegister');
Route::post('/register', 'Auth\AuthController#postRegister');
When i click on Register button nothing happen... the form do not submit, no errors etc.
Can you help me ?
Change this
<button type="button" class="btn btn-default">Register</button>
to
<button type="submit" class="btn btn-default">Register</button>
and always use dynamic url so that when you deploy your app to server,then you get no error(s)
action="{{ url('/register') }}
Change the type of the button:
<button type="submit"

Bootstrap 3.1 with laravel 4.0

I have problem to display confirmation dialog box when I click the delete button it show the confirmation dialog and also submit the form without clicking the button in confirmation dialog box.
I'm using bootstrap and laravel. here is the code.
<div class="modal fade" id="confirmDelete" role="dialog" aria-labelledby="confirmDeleteLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Delete Confirmation</h4>
</div>
<div class="modal-body">
<p>Are you sure you want to delete this data(s) ?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn default" data-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-danger" id="confirm">Delete</button>
</div>
</div>
</div>
$('#confirmDelete').on('show.bs.modal', function (e) {
// Pass form reference to modal for submission on yes/ok
var form = $(e.relatedTarget).closest('form');
$(this).find('.modal-footer #confirm').data('form', form);
});
<!-- Form confirm (yes/ok) handler, submits form -->
$('#confirmDelete').find('.modal-footer #confirm').on('click', function(){
$(this).data('form').submit();
});
{{ Form::open(array('route' => array('subscription.delete.all'), 'method' => 'delete')) }}
<button class='btn btn-xs btn-danger' type='submit' data-toggle="modal" data-target="#confirmDelete">
<i class='glyphicon glyphicon-trash'></i> Delete
</button>
{{ Form::close() }}
on top of your modal add this
<a href="#" type="button" class="btn btn-default btn-danger" data-toggle="modal" data-target="#confirmDelete">
delete
and in your modal code change the button
<button type="button" class="btn btn-danger" id="confirm">Delete</button>
by your delete button code
{{ Form::open(array('route' => array('subscription.delete.all')......
Change button (inside the form) type from "submit" to "button"

Resources