I'm working with group routes
on laravel 5.2
and I'm having problem with the create.store part of the route that saves my object.
My files are structured as follows:
ClientController.php
<?php
namespace App\Http\Controllers;
use Request;
use App\Http\Requests\CategoriaRequest;
use App\Categoria;
class CategoriaController extends Controller
{
public function index(){
$categorias = Categoria::all();
if(Request::wantsJson()){
return $categorias;
}else{
return view('Categoria.listCategoria', compact('categorias'));
}
}
public function create(){
$categoria = new Categoria();
return view('Categoria.cadCategoria', compact('categoria'));
}
public function store(CategoriaRequest $resquest){
dd($resquest);
$categoria = Categoria::create($resquest->all());
if(Request::wantsJson()){
return $categoria;
}else{
return view('Categoria.listCategoria', compact('categoria'));
}
}
public function show(Categoria $categoria){
if(Request::wantsJson()){
return $categoria;
}else{
return view('Categoria.showCategoria', compact('categoria'));
}
}
public function edit(Categoria $categoria){
return view('Categoria.editCategoria', compact('categoria'));
}
public function update(CategoriaRequest $request, Categoria $categoria){
$categoria->update($request->all());
if(Request::wantsJson()){
return $categoria;
}else{
return view('Categoria.listCategoria');
}
}
public function destroy(Categoria $categoria){
$deleted = $categoria->delete();
if(Request::wantsJson()){
return (string) $deleted;
}else{
return view('Categoria.listCategoria');
}
}
}
CategoryRequest.php
class CategoriaRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'NmCategoria' => 'required|min:5',
'DscCategoria' => 'required|min:5'
];
}
}
My model Categoria
class Categoria extends Model
{
protected $fillable = ['NmCategoria', 'DscCategoria'];
}
And my route looks like this:
Route::group(['middleware' => ['web']], function (){
Route::resource('categorias', 'CategoriaController');
});
My first problem is when I am clicking on edit, my query is id, my field is CdCategory, thus giving error in the query:
SQLSTATE [42S22]: Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select * from
categorias
whereid
= 1 limit 1)
What could it be?