Skip to content

Instantly share code, notes, and snippets.

@marufmax
Last active March 23, 2018 21:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marufmax/124c88477994c4196a1eefe2ba34e3a7 to your computer and use it in GitHub Desktop.
Save marufmax/124c88477994c4196a1eefe2ba34e3a7 to your computer and use it in GitHub Desktop.
Laravel Delete Action with JS
<a class="btn btn-outline-secondary" onclick="
var result = confirm('Are you sure you wish to delete this project?');
if (result) {
event.preventDefault();
document.getElementById('delete-form').submit();
}"
>Delete</a>
<form id="delete-form" action="{{ route('companies.destroy', [$company->id]) }}" method="POST" style="display: none;">
<input type="hidden" name="_method" value="delete">
{{ csrf_field() }}
</form>
public function update(Request $request, Company $company)
{
$companyUpdate = Company::where('id', $company->id)
->update([
'name' => $request->input('name'),
'description' => $request->input('description')
]);
if ($companyUpdate) {
return redirect()->route('companies.show',['company'=>$company->id])->with('success','Company Updated Successfully');
}
return back()->withInput();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment