如何在Laravel中将数据从一个表发送到另一个表?

时间:2017-02-28 14:26:56

标签: php laravel laravel-5

我将数据从一个表发送到另一个表时遇到问题。我也希望从第一个表中删除数据。是否可以在一个按钮下执行该操作?我的记录在表格中。我不知道如何路由这个操作。

这是我的想法,但它没有用。我收到错误无效的路线行动

    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');
}

我的路线是Route :: post('potwierdzone / $ id / dodaj /','PotwierdzonaController');

2 个答案:

答案 0 :(得分:0)

您应该使用migrations并使用transactions

答案 1 :(得分:0)

您没有为路线添加动作。好的做法是使用命名路线:

Route::get('potwierdzone/{id}/dodaj', ['as' => 'dodaj', 'uses' => 'PotwierdzonaController@dodaj']);

构建链接的route()助手:

<a href="{{ route('dodaj', $propozycja->id) }}">

<强>更新

使用此代码可以避免其他错误:

$operacje = Operacja::find($id);
Potwierdzona::create($operacje->toArray());
$operacje->delete();
return redirect('patients');
相关问题