1
votes

Column not found: 1054 Unknown column '_method' in 'field list'

Getting the above unknown column error for _method and _token but I have $fillable set in my model. What could be causing the error? I know the solution is Input::except('_method') in my controllers but I would like to understand the context of the issue. Here is my code

protected $table = 'personaldetails';

protected $fillable = [
'address',
'city',
'country',
'postcode',
];

The relavant top part of my blade form...

<form action="{{ route('students.update', [$student->id]) }}" method="POST">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" value="{{ Session::token() }}" name="_token">
<div class="row">

also tried with laravel { { csrf_field() } }.

  public function update(Request $request, $id)
{
    $inputData = $request->all();
    $Student = Student::find($id); 
    $Student->personaldetail()->update($inputData);
    return redirect()->route('Student.index')->with('message','Studenthas been updated'); }

Anyone else come across this too?

1
In which way are you saving your data? And how do you fill the attributes? This error could occur, for instance, when using the create() method in the wrong context. Can you show more of the controller code?Jan Willem
Not rly sure what the question is u said u know the solution? U said u want to know the error. The general explanation is that it seems you are trying to save all form values to your model with the column name being the "name" attribute and the value being the value of the form data. For _method you don't actually want to save that to the model so you either don't save t the way you are currently doing or you use the except method to prevent trying to save that value to the model. Do you have a question on one of those steps?tam5
@JanWillem and tam I have added my controller that is bringing this error up. I am unclear why it tries to store _method and _token. These are not form values I want to store.Eden WebStudio

1 Answers

1
votes

Per your comment response:

@JanWillem and tam I have added my controller that is bringing this error up. I am unclear why it tries to store _method and _token. These are not form values I want to store.

It's trying to store _method and _token because you're attempting to update the model w/ these attributes: $Student->personaldetail()->update($inputData);

As you've alluded to, you'll need to prune the list of attributes you'd like to update within the model from $inputData = $request->all(); to $inputData = $request->except('_method', '_token');