我的数据没有保存到数据库,我也没有收到错误
My data isnt being saved to database and im not getting an error
我遇到了一个问题,这段代码刚刚执行并且 vardump 显示了我在文本字段中输入的变量,但是数据库中没有显示任何数据,也没有错误显示
查看:
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet" type="text/css">
<body>
<div>
<form method="post" action="/post">
{{ csrf_field() }}
<input type="text" name="email">
<input type="text" name="password">
<input type="submit" name="submit">
</form>
</div>
</body>
</head>
</html>
控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\werknemer_model;
class werknemer extends Controller
{
/*Show the form for creating a new resource.*/
public function create(Request $request)
{
$email = $request->input('email');
var_dump($email);
$werknemer = new werknemer();
$werknemer->store($request);
return view('login_portal');
}
}
型号:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\controllers\werknemer
class werknemer_model extends Model
{
public function store (Request $request){
$email = $request->input('email');
$password = $request->input('password');
$werknemer = new werknemer;
$werknemer->id = 1;
$werknemer->bedrijf_id = 1;
$werknemer->email = $email;
$werknemer->naam = $password;
$werknemer->save();
try {
DB::connection()->getPdo();
} catch (\Exception $e) {
die("Could not connect to the database. Please check your configuration.");
}
}
}
路线:
Route::get('/', function () {
return view('Login_portal');
});
Route::post('/post','werknemer@create');
问题:我的数据没有保存到数据库,我没有收到错误
常见问题,容易忘记。您忘记在模型中设置变量(用于质量分配)。检查要放入数据库的数据并将其设置在模型中。
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Flight extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'another_data', 'another_variable'];
}
据我所知,您的模型结构不符合 Laravel 惯例。阅读并节省日后时间:https://laravel.com/docs/5.6/eloquent#mass-assignment
我遇到了一个问题,这段代码刚刚执行并且 vardump 显示了我在文本字段中输入的变量,但是数据库中没有显示任何数据,也没有错误显示
查看:
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Lato:100" rel="stylesheet" type="text/css">
<body>
<div>
<form method="post" action="/post">
{{ csrf_field() }}
<input type="text" name="email">
<input type="text" name="password">
<input type="submit" name="submit">
</form>
</div>
</body>
</head>
</html>
控制器:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\werknemer_model;
class werknemer extends Controller
{
/*Show the form for creating a new resource.*/
public function create(Request $request)
{
$email = $request->input('email');
var_dump($email);
$werknemer = new werknemer();
$werknemer->store($request);
return view('login_portal');
}
}
型号:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\controllers\werknemer
class werknemer_model extends Model
{
public function store (Request $request){
$email = $request->input('email');
$password = $request->input('password');
$werknemer = new werknemer;
$werknemer->id = 1;
$werknemer->bedrijf_id = 1;
$werknemer->email = $email;
$werknemer->naam = $password;
$werknemer->save();
try {
DB::connection()->getPdo();
} catch (\Exception $e) {
die("Could not connect to the database. Please check your configuration.");
}
}
}
路线:
Route::get('/', function () {
return view('Login_portal');
});
Route::post('/post','werknemer@create');
问题:我的数据没有保存到数据库,我没有收到错误
常见问题,容易忘记。您忘记在模型中设置变量(用于质量分配)。检查要放入数据库的数据并将其设置在模型中。
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Flight extends Model
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['name', 'another_data', 'another_variable'];
}
据我所知,您的模型结构不符合 Laravel 惯例。阅读并节省日后时间:https://laravel.com/docs/5.6/eloquent#mass-assignment