vendredi 23 août 2019

Form Select Storing ID instead of NAME

Im trying to store the selected value(name) which was retrieved from mysql but it storing the id instead of name? any suggestion?

Views



Route

Route::get('/', function () {
    $departments=Department::pluck('name','id');
    return view('index',compact('departments'));
});

Controller

public function store(Request $request)
    {
        $this->validate(request(), [
            'fname' => 'required',
            'lname' => 'required',
            'staffId' => 'required',
            'email' => 'required|email',
            'dept' => 'required',
            'role' => 'required',
            'password' => 'required|confirmed'
        ]);
        $departments=Department::pluck('name','id');
        $departments->name = $request ->input('dept');
        $user = User::create(request(['fname','lname','staffId','email','dept','role','password']));

        auth()->login($user);

        return redirect()->to('/home2');
    }

Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Department extends Model
{
    protected $fillable=['name'];
    protected $table='department';

}




via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire