0
votes

I have an error when I try to acces to my tipos/index page, i'm using laravel 4 framework with jeffrey way generator to speed up the creation process of routes, controllers, models, etc.

This is my code:

Route:

Route::get('tipos/index', 
    array(
        'as' => 'index',
        'uses' => 'TiposController@index')
);

Model:

class Tipo extends Eloquent{

    protected $guarded = array();

        public static $rules = array(
        'clave_tipo' => 'required',
        'nombre_tipo' => 'required',
        'status' => 'required',
        'created_by' => 'required',
    );
}

Controller:

class TiposController extends BaseController {

protected $tipo;

public function index() 
    {
        $tipos = $this->tipo->all();
        return View::make('tipos.index', compact('tipos'));
    }

Especific Route in my master.blade:

{{ link_to('tipos/index', trans('common/messages.tipos'))}} |

index.blade:

@extends('layouts.master')

@section('content')
    <h1>
        Tipos
    </h1>

<form name="form" id="form" method="post">

 <a class="editar button clear" href="/sistema/crearTipo">Nuevo Tipo</a>
    <input type="button" onclick="javascript:exportar();" value="Exportar" class="button" style="margin: 0px;">
    <input type="hidden" name="format" id="format" value="yy-mm-dd">
    <input type="hidden" name="excel" id="excel" value="false">
 <br><br>

<iframe name="x" height="0" width="0" style="display: none;"></iframe>

<div class="title">
    <form name="form" id="form" method="post">
        <iframe name="x" height="0" width="0" style="display: none;"></iframe>
        <table class="datatable" id="tipos">
            <thead>
                <th>C&Oacute;DIGO</th>
                <th>DESCRIPCI&Oacute;N</th>
                <th>EDITAR</th>
                <th>ELIMINAR</th>
            </thead>

        </table>
    <div class="foot">

    </div>
    </form>
</div> 
@stop

And this error appears: Illuminate \ Database \ Eloquent \ ModelNotFoundException No query results for model [Tipo].

If anyone can help I will be grateful!

3
You have no records in the database. Handle the exception before you access the view.N.B.
I didn't see a protected $table = ''; in you're model!ArjanSchouten
Hi, I added to my model: protected $table = 'tipos'; but still get the error: No query results for model [Tipo].Ramiro Arizpe Giacomelli

3 Answers

1
votes

Solved, i have two routes of tipos:

Route::resource('tipos', 'TiposController');

AND

Route::get('tipos/index', 
    array(
        'as' => 'index',
        'uses' => 'TiposController@index')
);

Just remove the the duplicate route tipos/index and put in mi master.blade:

{{ link_to**_route**('tipos.index', trans({{'common/messages.tipos'))}} |

The conflict was because i needed the _route in mi master.

Thanks!.

0
votes

You need to inject your Tipo model into the controller.

class TiposController extends BaseController {

    protected $tipo;

    function __construct(Tipo $tipo){
        $this->tipo = $tipo;
    }

}

Not sure why you get the ModelNotFoundException because you never injected the Model in your controller. Does your tipos table have records in it?

0
votes

I had same issue. I place index route after single singe list. Then i just place index task before single list. Then it's works.

Route::get('index', 'TasksController@index');

Route::get('/{task}', 'TasksController@single');

It's wired but worked!