<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\RegisterController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/
Route::get('/home', [RegisterController::class, 'index'])->name('home');
Route::get('/home/create', [RegisterController::class, 'create'])->name('create');
Route::post('/home', [RegisterController::class, 'store'])->name('store');
#Form doesn't send information to database
31 messages · Page 1 of 1 (latest)
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Register;
class RegisterController extends Controller
{
public function index(){
return view('index');
}
public function create(){
return view('create');
}
public function store(Request $request) {
$data = $request->validate([
'naam' => 'required',
'land' => 'required',
'beschrijving' => 'required',
'age' => 'required',
]);
$newKaas = Register::create($data);
return redirect(route('index'));
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Create product</h1>
<form method="post" action="{{route('store')}}">
@csrf
@method('post')
<div>
<label for="name">Name</label>
<input type="text" name="name" placeholder="name">
</div>
<div>
<label for="land">Land</label>
<input type="text" name="land" placeholder="land">
</div>
<div>
<label for="beschrijving">Beschrijving</label>
<input type="text" name="beschrijving" placeholder="beschrijving">
</div>
<div>
<label for="nummer">Age</label>
<input type="number" name="nummer" placeholder="nummer">
</div>
<div>
<button type="submit">Create</button>
</div>
</form>
</body>
</html>
Where exactly in the form?
Hmm still no change
isn't this code exactly the same as i've given
Yes that is correct, however you should change it to read name="naam" as shown in your validate logic
Still not working
<div>
<label for="naam">Name</label>
<input type="text" name="naam" placeholder="naam">
</div>
Other auxillary checks, would be checking mass assignment and if the other fields have been created with nullable()
Additionally, this is also wrong <label for="nummer">Age</label> <input type="number" name="nummer" placeholder="nummer"> </div>
it should read name="age"
No problem, you are welcome
ONly now i am running in to a problem it isn't going to the Table it should be in
In that case please check your Register::create method.
$newKaas = RegisterController::create($data);
My controller is Called RegisterController so that's right
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Register extends Model
{
use HasFactory;
protected $fillable = [
'naam',
'land',
'beschrijving',
'age',
];
}
``` This is my modle
model
What table is it going into?
kaas_register
OK I'm not sure, assuming you've followed the tutorial on how to make models, migrations and using eloquent ORM correctly, it should work.
For the record, I don't use the ORM facility.
Hmm weird