Muhammad Arslan Muhammad Arslan - 1 year ago 53
MySQL Question

data type for character and numbers in laravel

I want to store character and numbers for column have primary key in database.

I created the table through query in laravel like this

public function up()
Schema::create('students', function (Blueprint $table) {
// $table->increments('id');
$table->engine = 'InnoDB';



and set my column datatype string. which shows varchar in database looking fine. When i enter values in form the data stored perfectly like 12abc but when i fetch data from database it shows only 12 without characters.
And the function is

public function showStudents()
$allStudents = Student::all();
// $user = Auth::user();
return view ('admin.students.showStudents', compact('allStudents'));

and loop is

@foreach($allStudents as $student)
<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>

What should i do to get proper and complete data. Thanks in advance.

Answer Source

Just paste this line to your model. So that modal can handle it without auto increment field.

public $incrementing = false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download