I am building a test blog site in laravel 5.2 and trying to create a page to manage all categories. So far, everything is working fine, but I would like to have a table with a list of categories and edit each built-in. Usually I create a table and a foreach loop in it with a form for each row, but this time it does not work properly. I read that the form inside the table is bad practice, so I tried to make it only with a div, but it does not work either.
Here is the view code:
@foreach($categories as $category)
<form action="/blog/categories/edit/{{ $category->id }}" method="post">
<div class="row">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="col-md-2"><input type="text" value="{{ $category->id }}" name="id" class="category-input-id" readonly="readonly"></div>
<div class="col-md-2">{{ $category->created_at }}</div>
<div class="col-md-2">{{ $category->updated_at }}</div>
<div class="col-md-2">
<label for"edit" class="btn btn-primary"><i class="fa fa-pancil"></i></label>
<input type="submit" id="edit" name="edit" class="hidden" />
<label for="delete" class="btn btn-danger"><i class="fa fa-trash"></i></label>
<input type="submit" id="delete" name="delete" class="hidden" />
</div>
</div>
</form>
@endforeach
In the controller:
public function editcategory (Request $request, $id)
{
dd($request->all());
}
I did not paste all the code to get the data, because I am not getting the data I need here.
The output is just the first line in the loop! Whenever I click, it only gets the first element.
array:5 [▼
"_token" => "wUhnsw8AoAuUDsuElALg8nM91bFG4EkUHTEAkkjp"
"id" => "16"
"name" => "Category Name"
"description" => "desc test"
"edit" => "Send"
]
?
(, name= "description []" ..), , , !