简体   繁体   English

在 Laravel 中创建一个插入表单

[英]Create an Insert form in laravel

I'm trying to create an Insert form in laravel to add new information on a MySQL database, but I don't know how to do it.我正在尝试在 laravel 中创建一个插入表单以在 MySQL 数据库上添加新信息,但我不知道该怎么做。 I have this code, but I don´t know hot to code it in laravel我有这个代码,但我不知道在 Laravel 中编写代码

$vide= $_POST['idelic'];
  $vnom= $_POST['nomemp'];
  $vequ= $_POST['equlic'];
  $vnoms= $_POST['nomsof'];
  $vord= $_POST['ordcom'];
  $videp= $_POST['idemp'];

  $insert= "insert into lic values ('$vide', '$vnom', '$vequ', '$vnoms', '$vord', '$videp')";
  $result= mysqli_query($conect, $insert);

  if ($result) {
     echo "<script>
            alert('Insertado exitosamente');
            window.location= 'Insertar_Licencia.php'
</script>";

Could anybody help me?有人可以帮我吗? Thank you in anvance.提前谢谢你。

It looks like we must start from the beginning.看来我们必须从头开始。 First, you'll need a License model.首先,您需要一个许可证模型。

Use this artisan command to generate the Model , the Controller and the Migration .使用这个 artisan 命令来生成模型控制器迁移

php artisan make:model License -mc

Please read about how to access the request data here在此处阅读有关如何访问请求数据的 信息

A really simplified example would be:一个真正简化的例子是:

public function store(Request $request)
{
    $lic = new License;
    $lic->vnom = $request->input('nomemp');
    $lic->vequ = $request->input('equlic');
    $lic->vnoms= $request->input('nomsof');
    $lic->vord = $request->input('ordcom');
    $lic->videp= $request->input('idemp');
    $lic->save();

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM