我想在数据库中存储具有主键的列的字符和数字。
我像这样在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/