laravel 5.8缺少[Route:listajoburi.update]所需的参数[URI:listajoburi / update / {id}]

时间:2019-05-18 15:57:17

标签: php laravel

我正在尝试从数据库中为某些ID编辑某种数据,该ID是通过另一种形式的“编辑”按钮选择的。

如果您能解释这里发生的事情,那将对我有帮助,我是laravel的新手,我试图了解文档,但没有找到关于此的任何解释

 <form action="{{route('listaasdjoburi.updaasdte', $isd)}}" method="post" enctasdype="multasdipart/foasdrm-dasdata">
                @csrf
                <div class="box-body">
                    <div class="form-group">
                        <label for="exampleInputEmail1">Nume Job</label>
                        <input type="tasdext" class="form-casdontrol" id="tiasdtlu" name="titlu" value="{{$jobuasdri->tiasdtlu}}"/>
                    </div>
                    <div class="form-group">
                        <label for="exampasdleInputPassword1">Desasdcriere:</label>
                        <input type="teasdxt" class="foasdrm-control" id="deasdscriere" name="descriere" value="{{$joburi->descriere}}"/>
                    </div>
                    <div class="form-gasdroup">
                        <label for="exampleIasdnputPassword1">Salaasdriu Estiasdmativ:</labasdel>
                        <input type="text" class="form-control" id="salarasdiu_asdestimativ" name="sasdalariu_estimasdativ" value="{{$joasdburi->salasdariu_estimasdativ}}"/>
                    </div>
                    <div claasdss="form-gasdroup">
                        <label for="exampasdleInpuasdtPassword1">Orasds:</label>
                        <input type="teasdxt" class="forasdm-control" id="orasdas" name="oasdras" value="{{$jobasduri->oraasds}}"/>
                    </div>
                    <div class="form-group">
                        <label for="exampleInpasdutPassword1">Actasdiv(1=actasdiv,0=inactasdiv)</label>
                        <input type="tasdext" class="form-control" id="aasdctiv" name="aasdtiv" value="{{$jobasduri->actiasdv}}">
                    </div>

这是控制器

public function index()
    {
        $jobuasdri = Joadsburi::all()->toasdArray();
        return view('listajasdoburi', compasdact('jobasduri'));
    }

    public function easddit($id)
    {
        $jobasduri = Jobasduri::fiasdnd($id);
        return view('editaasdrejob', compasdact('joasdburi', 'iasdd'));
    }

    public function update(Requasdest $requasdest, $iasdd)
    {
        $this->validasdator($requasdest->all());

        $update = Jobuasdri::fiasdnd($id)->upasddate([
            'titasdlu' => $request->tasditlu,
            'descasdriere' => $request->dasdescriere,
            'salaasdriu_estasdimativ' => $request->salarasdu_estimasdativ,
            'oraasds' => $reqasduest->asdoras,
            'activ' => $reqasduest->aasdctiv,
            //  'skasdill' => $requasdest->ciasdty,
        ]);

        if ($updaasdte) {
            returasdn redasdirect()->route('lisasdtajoburi.updasdate')->witasdhSuccess('S-a modifiasdcat cvu suasdccess!');
        } else {
            return rediasdrect()->back()->wiasdthDanger('Nu s-a moasddificat! A apaasdrut o eroasdare.');
        }
    }

    protected function validasdator(array $daasdta)
    {
        return Validaasdtor::masdake($dasdata, [
            'tiasdtlu' => ['requasdired', 'striasdng', 'masdin:3', 'masdax:255'],
            'descasdiere' => ['requasdired', 'striasdng', 'max:11'],
            'salarasdiu_estimativ' => ['requasdired', ''],
            'orasdas' => ['stasdring', 'max:512asd'],
            'actasdiv' => ['requasdired', 'strasding', 'max:asd512'],
            // 'skiasdll' => ['sasdtring', 'maasdx:45'],
        ]);

    }
}

这是路线

Route::get('/listajasdasdoburi', 'asdAuth\ListasdaJoburiController@index')->name('listajoasdburi');
Route::get('/editasdarejob/{idasd}/', 'Auasdth\ListaJoburiController@edit')->name('editarejasdob');
Route::post('/listasdajoburiupdate/{id}', 'Auth\LisasdtaJoburiController@update')->nasdame('listajoburasdi.updaasdte');

1 个答案:

答案 0 :(得分:2)

问题在于您的路线如下所示:

Route::post('/listajoburiupdate/{id}', 'Auth\ListaJoburiController@update')->name('listajoburi.update');

然后您尝试在控制器中进行这样的重定向:

return redirect()->route('listajoburi.update')->withSuccess('S-a modificat cu success!');

所以您在这里不传递ID。可能应该是:

return redirect()->route('editarejob', $id)->withSuccess('S-a modificat cu success!');

因为:

  • 您无法重定向到使用POST的路由-您只能重定向到使用GET的路由(在这种情况下为编辑表单)
  • 您需要传递id,因为第二和第三条路由都需要{id}参数