Laravel 5.2无法更新记录

Laravel 5.2无法更新记录,laravel,routes,laravel-5.2,Laravel,Routes,Laravel 5.2,我似乎无法更新我的记录 我的控制器 public function add() { return view('cars.add'); } public function edit($id) { $car = Cars::whereId($id)->firstOrFail(); return view('cars.edit', compact('car')); } public function store(CarFormRequest $request) {

我似乎无法更新我的记录

我的控制器

public function add()
{
    return view('cars.add');
}

public function edit($id)
{
    $car = Cars::whereId($id)->firstOrFail();
    return view('cars.edit', compact('car'));
}

public function store(CarFormRequest $request)
{
    $car = new Cars(array(
        'name' => $request->get('name'),
        'color_id' => $request->get('color')
    ));

    $car->save();
    $car->position_id = $car->id;
    $car->save();

    session()->flash('status', 'Successfully Added a Car!');
    return view('cars.add');
}

public function update($id, CarFormRequest $request)
{
    $car = car::whereId($id)->firstOrFail();
    $car->name = $request->get('name');
    $car->color_id = $request->get('color');
    if($request->get('status') != null) {
        $car->status = 0;
    } else {
        $car->status = 1;
    }
    $car->save();
    return redirect(action('CarController@edit', $car->id))->with('status', 'The ticket '.$id.' has been updated!');

}
我的路线:

Route::get('/', 'PagesController@home');
Route::get('/about', 'PagesController@about');
Route::get('/contact', 'PagesController@contact');
Route::get('/cars', 'CarsController@index');
Route::get('/cars/edit/{id?}', 'CarsController@edit');
Route::post('/cars/edit/{id?}', 'CarsController@update');
Route::get('/cars/add', 'CarsController@add');
Route::post('/cars/add', 'CarsController@store');
以下是我的看法:

<div class="container col-md-8 col-md-offset-2">
<div class="well well bs-component">
    <form class="form-horizontal" method="post">
        <input type="hidden" name="_token" value="{!! csrf_token() !!}">
        <input type="text" id="color_id" name="color_id" value="{!! $car->color_id !!}">
        <fieldset>
            <legend>Edit Car Information</legend>
            <div class="form-group">
                <label for="title" class="col-lg-2 control-label">Car Name</label>
                <div class="col-lg-10">
                    <input type="text" value="{{ $car->name }}" class="form-control" id="name" placeholder="Car Name">
                </div>
            </div>
            <div class="form-group">
                <label for="title" class="col-lg-2 control-label">Car Color</label>
                <div class="col-lg-10">
                    <div class="btn-group" data-toggle="buttons">
                        <label id="opt1" class="btn btn-primary">
                            <input type="radio" name="color" id="option1" autocomplete="off"> Red
                        </label>
                        <label id="opt2" class="btn btn-primary">
                            <input type="radio" name="color" id="option2" autocomplete="off"> Blue
                        </label>
                        <label id="opt3"  class="btn btn-primary">
                            <input type="radio" name="color" id="option3" autocomplete="off"> Yellow
                        </label>
                        <label id="opt4" class="btn btn-primary">
                            <input type="radio" name="color" id="option4" autocomplete="off"> Green
                        </label>
                        <label id="opt5" class="btn btn-primary">
                            <input type="radio" name="color" id="option5" autocomplete="off"> Black
                        </label>
                        <label id="opt6" class="btn btn-primary">
                            <input type="radio" name="color" id="option6" autocomplete="off"> White
                        </label>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <div class="col-lg-10 col-lg-offset-2">
                    <button class="btn btn-default">Cancel</button>
                    <button type="submit" class="btn btn-primary">Submit</button>
                </div>
            </div>
        </fieldset>
    </form>
</div>
</div>

编辑汽车信息
车名
汽车颜色
红色
蓝色
黄色的
绿色
黑色
白色
取消
提交

其中的
$id
变量必须是数组,您还需要指定数据库列。这应该是-

public function edit($id)
{
    $car = Cars::whereId('id', [$id])->firstOrFail();
    return view('cars.edit', compact('car'));
}
更改所有发生的

$car = car::whereId($id)->firstOrFail();

为什么你在路线中使用
{id?}
而不是
{id}
呢?你能分享你的blade/html表单结构吗?我在一个教程中看到了他们在其中使用的,有什么区别吗?当你在哪个控制器上使用
dd($car)
?@jilsontomas时,你得到了什么?什么是dd?