如何在laravel中生成唯一的学生ID(例如2014-444-168)

时间:2016-05-03 15:17:53

标签: php laravel laravel-5.1

我正在创建一个注册系统,该系统应在提交表单时生成唯一的学生ID。唯一ID不包含在表单字段中。相反,它将使用 Prefix Verb URI Pattern Controller#Action root GET / sites#index sites GET /sites(.:format) sites#index POST /sites(.:format) sites#create new_site GET /sites/new(.:format) sites#new edit_site GET /sites/:id/edit(.:format) sites#edit site GET /sites/:id(.:format) sites#show PATCH /sites/:id(.:format) sites#update PUT /sites/:id(.:format) sites#update DELETE /sites/:id(.:format) sites#destroy scores GET /scores(.:format) scores#index POST /scores(.:format) scores#create new_score GET /scores/new(.:format) scores#new edit_score GET /scores/:id/edit(.:format) scores#edit score GET /scores/:id(.:format) scores#show PATCH /scores/:id(.:format) scores#update PUT /scores/:id(.:format) scores#update DELETE /scores/:id(.:format) scores#destroy new_user_session GET /users/sign_in(.:format) devise/sessions#new user_session POST /users/sign_in(.:format) devise/sessions#create destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy user_password POST /users/password(.:format) devise/passwords#create new_user_password GET /users/password/new(.:format) devise/passwords#new edit_user_password GET /users/password/edit(.:format) devise/passwords#edit PATCH /users/password(.:format) devise/passwords#update PUT /users/password(.:format) devise/passwords#update cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel user_registration POST /users(.:format) devise/registrations#create new_user_registration GET /users/sign_up(.:format) devise/registrations#new edit_user_registration GET /users/edit(.:format) devise/registrations#edit PATCH /users(.:format) devise/registrations#update PUT /users(.:format) devise/registrations#update DELETE /users(.:format) devise/registrations#destroy 类中的store方法生成。请参阅下面的代码。

StudentController

如上所示,我想创建学生ID。有人可以建议做上述任务的最佳做法

2 个答案:

答案 0 :(得分:0)

这将是独一无二的:

.container {
    overflow: hidden;
}
.col1,
.col2 {
    float: left;
    width: 50%;
}
.col2 {
    position: relative;
}
img {
    position: absolute;
    top: -100px;
    left: -100px;
}

即使这也是独一无二的:

$student->id_no = date("Y").'-'.$student->id;

因为它是自动递增的主键,因此无法复制。

答案 1 :(得分:0)

您可以将字符串附加到$student->id并生成类似但唯一的值。就像你在大学里找到的那​​样。