hi friends, I am following a tutorial of laravel 5.2 about an online sales page and I am in the administration panel;
The problem is that when trying to edit a category I have two problems;
-
My database is not loaded for each category, instead it loads the page but with the empty category data.
-
when trying to update any category (filling in the fields that come out empty) I get the following error;
MethodNotAllowedHttpException in RouteCollection.php line 233:
edit.blade
@extends('admin.template')
@section('content')
<div class="container text-center">
<div class="page-header">
<h1>
<i class="fa fa-shopping-cart"></i>
CATEGORÍAS <small>[Editar categoría]</small>
</h1>
</div>
<div class="row">
<div class="col-md-offset-3 col-md-6">
<div class="page">
@if (count($errors) > 0)
@include('admin.partials.errors')
@endif
{!! Form::model($category, array('route' => array('category.update', $category))) !!}
<input type="hidden" name="_method" value="PUT">
<div class="form-group">
<label for="name">Nombre:</label>
{!!
Form::text(
'name',
null,
array(
'class'=>'form-control',
'placeholder' => 'Ingresa el nombre...',
'autofocus' => 'autofocus'
)
)
!!}
</div>
<div class="form-group">
<label for="description">Descripción:</label>
{!!
Form::textarea(
'description',
null,
array(
'class'=>'form-control'
)
)
!!}
</div>
<div class="form-group">
{!! Form::submit('Actualizar', array('class'=>'btn btn-primary')) !!}
<a href="{{ route('admin.category.index') }}" class="btn btn-warning">Cancelar</a>
</div>
{!! Form::close() !!}
</div>
</div>
</div>
</div>
@stop
web.php
Route::get('category/create', [
'as' => 'admin.category.create',
'uses' => 'CategoryController@create'
]);
Route::get('category/store', [
'as' => 'admin.category.store',
'uses' => 'CategoryController@store'
]);
Route::get('category', [
'as' => 'admin.category.index',
'uses' => 'CategoryController@index'
]);
Route::get('category/edit/{id}', [
'as' => 'admin.category.edit',
'uses' => 'CategoryController@edit'
]);
Category.controller
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Category;
class CategoryController extends Controller
{
public function index()
{
$categories = Category::all();
//dd($categories);
return view('admin.category.index', compact('categories'));
}
public function create()
{
return view('admin.category.create');
}
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required|unique:categories|max:255',
]);
$category = category::create([
'name' => $request->get('name'),
'slug' => str_slug($request->get('name')),
'description' => $request->get('description'),
]);
$message = $category ? 'Categoría agregada correctamente!' : 'La Categoría NO pudo agregarse!';
return redirect()->route('admin.category.index')->with('message', $message);
}
public function show(Category $category)
{
return $category;
}
public function edit(Category $category)
{
return view('admin.category.edit', compact('category'));
}
}
Do you need any other information?