i am trynig to insert data in database when i click submit button it returns 404 not found
here is the controller
function ajouterfrm()
{
return view('dashboards.directeur.ajouter');
}
function add(Request $request)
{
$request->input();
}
and here is the routes
Route::get('rapport/ajouter',[DirecteurController::class,'ajouterfrm'])->name('directeur.ajouter');
Route::post('add',[DirecteurController::class,'add'])->name('directeur.add');
my html: here is my html
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3" style="margin-top: 50px">
<h4>Ajouter Rapport</h4>
<hr>
<form action="add" method="POST">
<input type="text" name="data_1" required>
<input type="text" name="data_2" required>
<!-- others inputs and selects ... -->
</form>
</div>
</div>
</div>
i tried to unname the last route but without any results
any suggestions?
thanks
Your form should look like this:
<form action="{{ route('directeur.add') }}" method="post">
@csrf // for preventing forgery token attacks otherwise you will get an "419 error"
<your inputs ...>
<form>
bonne chance.
Your add route doesn't do anything at this point, so no view or response is returned for the request.
You need to return something from your controller. Please see:
https://laravel.com/docs/8.x/responses
But for now you can try in your add function
return response('test');
here is my html
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3" style="margin-top: 50px">
<h4>Ajouter Rapport</h4>
<hr>
<form action="add" method="POST">
<div class="form-group">
<label for="">Titre</label>
<input type="text" name="titre" class="form-control" placeholder="Entrer le titre du rapp">
</div>
<div class="form-group">
<label for="">Description</label>
<textarea name="description" class="form-control" rows="3" placeholder="Entrer la description ici...">
</textarea>
</div>
<div class="form-group">
<label for="">Médecin</label>
<select class="form-control" name="medecin" id="">
<option value="med">Médecin 1</option>
<option value="med">Médecin 2</option>
<option value="med">Médecin 3</option>
</select>
</div>
<div class="form-group">
<label for="">Patient</label>
<select class="form-control" name="patient" id="">
<option value="pat">Patient 1</option>
<option value="pat">Patient 2</option>
<option value="pat">Patient 3</option>
</select>
</div>
<br>
<button type="submit" class="btn btn-primary btn-block">Ajouter</button>
</form>
</div>
</div>
</div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.