使用按钮将数据从一个表移动到另一个表Laravel [英] Move data from one table with button to another table Laravel

查看:168
本文介绍了使用按钮将数据从一个表移动到另一个表Laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在有人说这是重复的之前.是的,我已经找到了:

Before someone say this is a duplicate. Yes i have found this:

将数据从一个MySQL表移动到另一个

但是在Laravel中有点不同,这就是我想要的安静.像他一样,我想要一个按钮,以删除像这样的表格中的一行: (更新图片)

But in Laravel its a bit different this is quiet that what i want. Like him i want a button wich delete a row in a tabel like this one: (Updated picture)

仅举一个例子.单击按钮后,应将显示的行移到数据库中,就像此处显示的一样,然后将其删除.我真的不知道如何在laravel中启动这样的东西,我真的找不到相关的东西,所以如果您需要我刚刚告诉我的内容的代码片段,就可以告诉我.感谢您的帮助.

Just to have an example. After he hit the button it should move the shown row into the database just like it is shown here and delete it afterwards. I really dont know how to start something like this in laravel and i really cant find something related so if you need code snippets from what i have just tell me what you need. I appreciate every help thank you.

编辑

也许这将使其更加清晰:

Maybe this will make it more clearly:

$user_input = $request->userInput
$scores = DB::table('cd')
->join('customers', 'cd.fk_lend_id', '=', 'customer .lend_id')
->select('cd.fk_lend_id','cd.serialnumber','users.name', 'cd.created_at as lend on')
->where('cd.fk_lend_id',$request->$user_input)
->get();

推荐答案

假设您有两个表:firstsseconds 对于Laravel,这两个表必须具有两个模型:分别为FirstSecond.

Suppose you have two tables: firsts and seconds For Laravel you must have two Models for these two tables: First and Second respectively.

现在,在您的控制器中,

Now, in your controller,

//import your models
use App\First;
use App\Second;

//create a function which takes the id of the first table as a parameter
public function test($id)
{
    $first = First::where('id', $id)->first(); //this will select the row with the given id

    //now save the data in the variables;
    $sn = $first->serialnumber;
    $cust = $first->customer;
    $lendon = $first->lend_on;
    $first->delete();

    $second = new Second();
    $second->serialnumber = $sn;
    $second->customer = $cust;
    $second->lend_on = $lendon;
    $second->save();

    //then return to your view or whatever you want to do
    return view('someview);

}

记住上面的控制器功能是在单击按钮时调用的,并且必须传递id.

Remember the above controller function is called on button clicked and an id must be passed.

路线将是这样的:

Route::get('/{id}', [
    'as' => 'test',
    'uses' => 'YourController@test',
]);

而且,您的按钮链接如下:

And, your button link like:

<a href="{{ route('test',$id) }}">Button</a>

这篇关于使用按钮将数据从一个表移动到另一个表Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆