SQLSTATE[42S22]:找不到列:1054 'field list' 中的未知列 'created_by'
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'created_by' in 'field list'
我正在尝试将用户 ID 存储为 created_by ana 这是我的功能
public function store(Request $request)
{
$destinationPath = public_path('upload');
$image = $request->file('image');
$input['imagename'] = time() . '.' . $image->getClientOriginalExtension();
$image->move($destinationPath, $input['imagename']);
$dbPath = $destinationPath . "/" . $input['imagename'];
$hotel = new Hotel();
$hotel->name = $request->input('name');
$hotel->ville_id = $request->input('ville_id');
$hotel->price = $request->input('base_price');
$hotel->created_by=$request->input('created_by');
$hotel->content = $request->input('content');
$hotel->room = $request->input('room');
$hotel->stars = $request->input('stars');
$hotel->image = $input['imagename'];
$hotel->save();
toast('hotel ajouté !','success');
return redirect('/ahotels');
}
和酒店模特我有关系
class hotel extends Model
{
protected $fillable = [
'title', 'content','image','created_by',
];
public function user(){
return $this->belongsTo("App\User");
}
}
和用户模型
public function hotels(){
return $this->hasMany('App\hotel', 'created_by');
}
这是迁移
Schema::create('hotels', function (Blueprint $table) {
$table->id();
$table->string('name', 80);
$table->integer('ceated_by')->unsigned()->references('id')->on('users')->onDelete("cascade");
$table->string('image');
$table->timestamps();
我尝试刷新迁移但还是一样
迁移文件中的列拼写错误 'ceated_by'
与您的控制器方法不同 created_by
。请改成created_by
$table->integer('created_by')->unsigned()->references('id')->on('users')->onDelete("cascade");
我正在尝试将用户 ID 存储为 created_by ana 这是我的功能
public function store(Request $request)
{
$destinationPath = public_path('upload');
$image = $request->file('image');
$input['imagename'] = time() . '.' . $image->getClientOriginalExtension();
$image->move($destinationPath, $input['imagename']);
$dbPath = $destinationPath . "/" . $input['imagename'];
$hotel = new Hotel();
$hotel->name = $request->input('name');
$hotel->ville_id = $request->input('ville_id');
$hotel->price = $request->input('base_price');
$hotel->created_by=$request->input('created_by');
$hotel->content = $request->input('content');
$hotel->room = $request->input('room');
$hotel->stars = $request->input('stars');
$hotel->image = $input['imagename'];
$hotel->save();
toast('hotel ajouté !','success');
return redirect('/ahotels');
}
和酒店模特我有关系
class hotel extends Model
{
protected $fillable = [
'title', 'content','image','created_by',
];
public function user(){
return $this->belongsTo("App\User");
}
}
和用户模型
public function hotels(){
return $this->hasMany('App\hotel', 'created_by');
}
这是迁移
Schema::create('hotels', function (Blueprint $table) {
$table->id();
$table->string('name', 80);
$table->integer('ceated_by')->unsigned()->references('id')->on('users')->onDelete("cascade");
$table->string('image');
$table->timestamps();
我尝试刷新迁移但还是一样
迁移文件中的列拼写错误 'ceated_by'
与您的控制器方法不同 created_by
。请改成created_by
$table->integer('created_by')->unsigned()->references('id')->on('users')->onDelete("cascade");