So, what i`m trying to do here is to edit some data from database for a certain id wich is selected from the edit button in other form. here is the form for edit
It would help me if you can explain what is happening here, im new to laravel, I have tried to understand the documentation but I didnt find any explenation for this
<form action="" method="post" enctype="multipart/form-data">
@csrf
<div class="box-body">
<div class="form-group">
<label for="exampleInputEmail1">Nume Job</label>
<input type="text" class="form-control" id="titlu" name="titlu" value=""/>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Descriere:</label>
<input type="text" class="form-control" id="descriere" name="descriere" value=""/>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Salariu Estimativ:</label>
<input type="text" class="form-control" id="salariu_estimativ" name="salariu_estimativ" value=""/>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Oras:</label>
<input type="text" class="form-control" id="oras" name="oras" value=""/>
</div>
<div class="form-group">
<label for="exampleInputPassword1">Activ(1=activ,0=inactiv)</label>
<input type="text" class="form-control" id="activ" name="ativ" value="">
</div>
this is the controller
public function index()
{
$joburi = Joburi::all()->toArray();
return view('listajoburi', compact('joburi'));
}
public function edit($id)
{
$joburi = Joburi::find($id);
return view('editarejob', compact('joburi', 'id'));
}
public function update(Request $request, $id)
{
$this->validator($request->all());
$update = Joburi::find($id)->update([
'titlu' => $request->titlu,
'descriere' => $request->descriere,
'salariu_estimativ' => $request->salariu_estimativ,
'oras' => $request->oras,
'activ' => $request->activ,
// 'skill' => $request->city,
]);
if ($update) {
return redirect()->route('listajoburi.update')->withSuccess('S-a modificat cu success!');
} else {
return redirect()->back()->withDanger('Nu s-a modificat! A aparut o eroare.');
}
}
protected function validator(array $data)
{
return Validator::make($data, [
'titlu' => ['required', 'string', 'min:3', 'max:255'],
'descriere' => ['required', 'string', 'max:11'],
'salariu_estimativ' => ['required', ''],
'oras' => ['string', 'max:512'],
'activ' => ['required', 'string', 'max:512'],
// 'skill' => ['string', 'max:45'],
]);
}
}
and this is the route
Route::get('/listajoburi', 'Auth\ListaJoburiController@index')->name('listajoburi');
Route::get('/editarejob/{id}/', 'Auth\ListaJoburiController@edit')->name('editarejob');
Route::post('/listajoburiupdate/{id}', 'Auth\ListaJoburiController@update')->name('listajoburi.update');
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire