I have problem with send data from one table to another. I want delete data from first table too. Is it possible to do that operation under one button ? I have my records in table. I don't know how to route this operation.
This is my idea,but it didnt work. I get error Invalid route action
public function dodaj($id)
{
$operacje = DB::table('operacja')->where('id',$id)->get();
$operacje = DB::table('potwierdzona')->insert($operacje);
$operacje = Operacja::findorFail($id);
$operacje->delete();
return redirect('patients');
}
My route is Route::post('potwierdzone/$id/dodaj/','PotwierdzonaController');
You didn't add an action to the route. The good practice is to use named routes:
Route::get('potwierdzone/{id}/dodaj', ['as' => 'dodaj', 'uses' => 'PotwierdzonaController@dodaj']);
And the route()
helper to build links:
<a href="{{ route('dodaj', $propozycja->id) }}">
Update
Use this code to avoid other errors:
$operacje = Operacja::find($id);
Potwierdzona::create($operacje->toArray());
$operacje->delete();
return redirect('patients');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.