有人把这个问题标记为重复的问题,这很愚蠢。以下代码的哪一部分去了控制器,哪一部分去了模型?

时间:2019-04-02 13:38:45

标签: laravel-5.8

我正在开发一个应用程序,该应用程序可以跟踪有时在股东之间转移的公司股票(股票)。

以下是我的php页面代码:

<?php

// Collects the variables submitted from a simple html form

    if(isset($_POST['submit'])) {

        $count = $_POST['count'];
        $first = $_POST['first'];
        $last   = $_POST['last'];

    }

// A function that produces an array of serial numbers on the basis of first  // and last of the series and prefixes one or more letters as needed

$serialno = array_map(function($n) { return sprintf('A%05d', $n); }, range($first, $last) );


// Function to allocate unique identifier to each share 

$i = 0;

$identifier = array();

while ($i++ < $count)
{
    $identifier[] = strtoupper(uniqid());
}

// The above two results being array combnied

$stocklot = array_combine($serialno, $identifier);


// PDO insert for data to be written to mysql table

$stmt = $pdo->prepare("INSERT INTO stock_list (serialno, identifier) VALUES (?,?)");
try {
    $pdo->beginTransaction();
    foreach ($stocklot as $serialno => $identifier)
    {
        $stmt->execute( [ $serialno, $identifier ] );
    }
    $pdo->commit();
}catch (Exception $e){
    $pdo->rollback();
    throw $e;
}

?>

<form action="" method="POST" name="form">

Count: <input name="count" type="number">
First #<input name="first" type="number">
Last #<input name="last" type="number">

<input name="submit" type="submit" value="Submit">
<input name="reset" type="reset" value="Reset">

</form>`enter code here`

我的问题是我应该如何在Laravel mvc中组织这段代码?

0 个答案:

没有答案