Last active
March 23, 2018 21:47
-
-
Save marufmax/124c88477994c4196a1eefe2ba34e3a7 to your computer and use it in GitHub Desktop.
Laravel Delete Action with JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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