Php Laravel不接受我的数据库输入
我试图在数据库表中插入条目,但它不起作用。两周前它还在工作,但我发现我不小心改变了一些东西 我的相关模型、迁移和控制器都在这里 Model-Profile.phpPhp Laravel不接受我的数据库输入,php,mysql,laravel-5.1,laravel-routing,laravel-form,Php,Mysql,Laravel 5.1,Laravel Routing,Laravel Form,我试图在数据库表中插入条目,但它不起作用。两周前它还在工作,但我发现我不小心改变了一些东西 我的相关模型、迁移和控制器都在这里 Model-Profile.php <?php namespace App; use Illuminate\Database\Eloquent\Model; class Profile extends Model { // protected $table='profile'; protected $fillable=['user_
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Profile extends Model
{
//
protected $table='profile';
protected $fillable=['user_id', 'Gender', 'Age', 'Address'];
}
在迁移中,您使用大写的列名(即“性别”),而在尝试填充模型时使用小写的(“性别”)。此外,您从不保存模型:
$profile = new Profile(array('user_id'=>$uid, 'Gender'=>$input['gender'], 'Age'=>$input['age'], 'Address'=>$input['address']));
$profile->save(); // <- You need to call save() to persist the model to your database.
return view('welcome');
$profile=新配置文件(数组('user_id'=>$uid',Gender'=>$input['Gender'],'Age'=>$input['Age'],'Address'=>$input['Address']);
$profile->save();// 在下面:$profile=newprofile(数组('user_id'=>$uid,'gender'=>$input['gender'],'age'=>$input['age'],'address'=>$input['address'])代码>
警告:$profile->save()代码>
行动呢?of{!!Form::open(数组('class'=>'Form horizontal col-xs-10 col-sm-6 col-md-4'))!!
在使用$profile->save()后阅读此;我收到了这个错误-SQLSTATE[42S22]:未找到列:字段列表中1054未知列“updated_at”(SQL:insert-intoprofile
(user\u id
,updated_at
,created_at
)值(3,2015-12-04 16:28:402015-12-04 16:28:40))Putpublic$timestaps=false代码>在您的模型顶部。很高兴听到,Shawon!快乐编码!
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Auth;
use App\Profile;
use App\Http\Requests;
use Request;
use Carbon\Carbon;
//use App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
class profileController extends Controller
{
//
public function index(){
return view('pages.profile');
}
public function store(){
$uid=Auth::user()->id;
$input=Request::all();
$input['user_id']=$uid;
$profile = new Profile(array('user_id'=>$uid, 'gender'=>$input['gender'], 'age'=>$input['age'], 'address'=>$input['address']));
return view('welcome');
}
}
{!! Form::open(array('class' => 'form-horizontal col-xs-10 col-sm-6 col-md-4')) !!}
<!-- <form class="form-horizontal col-xs-10 col-sm-6 col-md-4 ">-->
<fieldset>
<!-- Form Name -->
<legend>User Profile</legend>
<!-- Multiple Radios -->
<div class="form-group">
<label class="col-md-4 control-label" for="gender">Gender</label>
<div class="col-md-4">
<div class="radio">
<label for="gender-0">
<input type="radio" name="gender" id="gender-0" value="1" checked="checked">
Male
</label>
</div>
<div class="radio">
<label for="gender-1">
<input type="radio" name="gender" id="gender-1" value="2">
Female
</label>
</div>
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="age">Age</label>
<div class="col-md-2">
<input id="age" name="age" type="text" placeholder="Age" class="form-control input-md">
</div>
</div>
<!-- Textarea -->
<div class="form-group">
<label class="col-md-4 control-label" for="address">Address</label>
<div class="col-md-8">
<textarea class="form-control" id="address" name="address">Address</textarea>
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="submit"></label>
<div class="col-md-4">
<button id="submit" name="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
<!--</form>-->
{!! Form::close() !!}
Route::get('profile', 'profileController@index');
Route::post('profile', 'profileController@store');
$profile = new Profile(array('user_id'=>$uid, 'Gender'=>$input['gender'], 'Age'=>$input['age'], 'Address'=>$input['address']));
$profile->save(); // <- You need to call save() to persist the model to your database.
return view('welcome');