Check the Laravel log file
500 server error on submit and delete of contact form
Hello. I launched my laravel application to the live server after running extensive tests locally. Every route and link worked fine. Now that it is live, I am having a problem submitting the contact form and on the backend, deleting the form entry data. I get a 500 server error and the url route in the address bar reflects either the store route or the delete route respectively. I am not sure on these particular routes, what I did wrong because all my other backend routes, edit, delete, etc work just fine. If anyone else can spot what I might have missed, I would sure appreciate it. Thank you in advance. Here is my Code: Store and Delete Routes:
Route::post('contact-form2', [ContactTwoController::class, 'storeContactForm2'])->name('contact-form2.store');
Route::get('delete_contact2/{id}', [ContactTwoController::class, 'deleteContactMessage2'])->name('delete_contact2');
My form tag
<form class="contact-form pb-3" method="post" id="contactform" action="{{ route('contact-form2.store') }}">
My Contact Controller
<?php
namespace App\Http\Controllers;
use App\Models\ContactTwo;
use Illuminate\Http\Request;
class ContactTwoController extends Controller
{
public function frontendTwoContactMessagesView() {
$frontendTwoMessages = ContactTwo::all();
return view('admin.contact_messages.frontend_two_messages_view', compact('frontendTwoMessages'));
}
protected function formResponse2() {
$notification = array(
'message' => 'Mensaje Enviado Exisotamente',
'alert-type' => 'success'
);
return redirect()->to('inicio')->with($notification);
}
public function storeContactForm2(Request $request)
{
if ($request->faxonly) {
return $this->formResponse2();
}
$request->validate([
'name' => 'required',
'mail' => 'required|email',
'mensaje' => 'required',
]);
$input = $request->all();
ContactTwo::create($input);
// Send mail to admin
\Mail::send('contact2Mail', array(
'name' => $input['name'],
'empresa' => $input['empresa'],
'mail' => $input['mail'],
'tel1' => $input['tel1'],
'tel3' => $input['tel3'],
'tel2' => $input['tel2'],
'pais' => $input['pais'],
'mensaje' => $input['mensaje'],
), function($message) use ($request){
$message->from('emailaddress');
$message->to('emailaddress', 'Admin')->subject($request->get('empresa'));
});
$notification = array(
'message' => 'Mensaje Enviado Exisotamente',
'alert-type' => 'success'
);
return Redirect()->route('contact_us')->with($notification);
}
public function ContactMessages2() {
$contacts = ContactTwo::all();
return view('admin.contacts', compact('contacts'));
}
public function deleteContactMessage2($id) {
$contact = ContactTwo::find($id);
$contact->delete();
$notification = array(
'message' => 'Message Successfully Deleted',
'alert-type' => 'success'
);
return Redirect()->route('frontend_two_messages')->with($notification);
}
}
By the way, I am receiving the data in the database and can see that data in the backend. But like I mentioned earlier, when I go to delete it, I get a 500 server error. when I go back and then refresh the page, the item shows as successfully deleted and is removed from the database.
So confused. Any help would be great. Thank you.
@ErikRobles the way it is meant to be deployed is with all the files in the laravel project in one folder (or child folders) and ONLY the public folder accessible from the outside. This is achieved by setting the public folder the document root This is an important term to get to grips with.
This is NOT a problem to be solved by tinkering with .htaccess
Please or to participate in this conversation.