jeudi 4 juin 2020

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'created_by' in 'field list'

im trying to store a user id as created_by ana this is my function

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');
}

and hotel Model i do relashionships

class hotel extends Model
{
    protected $fillable = [
        'title', 'content','image','created_by',
    ];

    public function user(){
        return $this->belongsTo("App\User");
    }

}

and user model

public function hotels(){
    return  $this->hasMany('App\hotel', 'created_by');
}

This is migration

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();

i try refresh migration but still the same



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire