作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想在数据库中存储具有主键的列的字符和数字。
我像这样在laravel中通过查询创建了表
public function up()
{
Schema::create('students', function (Blueprint $table) {
// $table->increments('id');
$table->engine = 'InnoDB';
$table->string('roll_no');
$table->string('name');
$table->string('father_name');
$table->string('address');
$table->string('cnic')->unique();
$table->string('phone_no');
$table->string('father_phone_no');
$table->string('email')->unique();
$table->string('password');
$table->string('dept_id');
$table->rememberToken();
$table->timestamps();
$table->primary('roll_no');
$table->foreign('dept_id')->references('dept_id')->on('departments')->onDelete('cascade');
});
}
并设置我的列数据类型字符串。这显示数据库中的 varchar 看起来不错。当我在表格中输入值时,数据存储得非常像 12abc 但是当我从数据库中获取数据时它只显示 12 没有字符。而函数是
public function showStudents()
{
$allStudents = Student::all();
// $user = Auth::user();
return view ('admin.students.showStudents', compact('allStudents'));
}
循环是
@foreach($allStudents as $student)
<tr>
<th scope="row">{{ $student->roll_no }}</th>
<td><a href="{{ action('AdminController@singleStudent', [$student->roll_no])}}">{{ $student->name }}</a></td>
<td>{{ $student->address }}</td>
<td>{{ $student->phone_no }}</td>
<td>{{ $student->email }}</td>
<td>{{ $student->dept_id }}</td>
<td><a href="{{ action('AdminController@editStudents', [$student->roll_no])}}" class="edit">Edit</a> <a href="{{ action('AdminController@deleteStudent', [$student->roll_no])}}" class="delete">Delete</a> </td>
</tr>
@endforeach``
我应该怎么做才能获得正确和完整的数据。提前致谢。
最佳答案
只需将此行粘贴到您的模型中。这样模式就可以在没有自动增量字段的情况下处理它。
public $incrementing = false;
关于mysql - laravel中字符和数字的数据类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37915968/
我是一名优秀的程序员,十分优秀!