#laravel form submit
6 messages · Page 1 of 1 (latest)
okay so i got a controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\TestDb;
class AccountController extends Controller
{
public function login()
{
$data = TestDb::all(); // Fetch all records from the test_db table
return view('layouts.Login.login', ['data' => $data]);
}
}
and a model:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class TestDb extends Model
{
use HasFactory;
protected $table = 'test_tb'; // Specify the table name explicitly
}
and a view:
<?php
if(DB::connection()->getPdo()) {
echo "Yes! I am connected to the database";
} else {
echo "Could not connect to the database.";
}
?>
<table>
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Street</th>
<th>Gender</th>
</tr>
</thead>
<tbody>
@foreach($data as $item)
<tr>
<td>{{ $item->name }}</td>
<td>{{ $item->age }}</td>
<td>{{ $item->street }}</td>
<td>{{ $item->gender }}</td>
</tr>
@endforeach
</tbody>
</table>
now i do get the data from the database
but how can i post stuff to the database