controller: UserController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class UserController extends Controller {
public function insertform() {
return view('contact-us');
}
public function enq()
{
$name = $this->input->post('name');
$phone = $this->input->post('phone');
$email = $this->input->post('email');
$msg = $this->input->post('msg');
$data=array('name'=>$name,"phone"=>$phone,"email"=>$email,"msg"=>$msg);
DB::table('enquiry')->insert($data);
echo "Record inserted successfully";
}
}
View: Contact-us.blade.php
<script>
$(document).ready(function(){
$("#submit").click(function(e){
e.preventDefault();
name = $("#name").val();
phone = $("#phone").val();
email = $("#email").val();
msg = $("#msg").val();
$.ajax({
type:"POST",
data:{"name":name,"phone":phone,"email":email,"msg":msg},
url:"/enq",
success:function(data){
$("#success").html(data);
}
});
});
});
</script>
<div id="success"></div>
<form method="post">
<input type="text" placeholder="Your Name" name="name" id="name">
<input type="text" placeholder="Phone Number" name="phone" id="phone">
<input type="text" placeholder="Email Adress" name="email" id="email">
<textarea placeholder="Massege" name="msg" id="msg"></textarea>
<input type="submit" name="submit" id="submit" value="submit now" class="btn-blue">
</form>
web.php
<?php
Route::get('contact-us', function () {
return view('contact-us');
});
Route::post('enq','UserController@enq');
I am new in laravel Here what am I doing I am going to insert a simple form value into database. Now, what happen when I click on submit button it show nothing. I have no idea about that. So, How can I do this? Please help me.
Thank You
F12on keyboard, if using chrome, inspect tool will open. Go toNetworktab. click onXHRsub tab. You will see yourenqurl call and now debug. If still ain't see anything then, in.envfileAPP_DEBUGset this totrue. Don't forget to fire terminal command,php artisan config:cacheto reflect config changes throughout the project.enqmethod()?