"Controller method not found." in a method that exists

Asked

Viewed 371 times

0

I’m starting with the and on a project that was already underway.
I’m trying to access the url http://mydomain.com.br/purchases/edit/1 and is always returning.

Symfony Component Httpkernel Exception Notfoundhttpexception
Controller method not found.

Since the controller has these two methods:

public function getEdit($id) {
    //
    try {
        $record = Purchase::whereId($id)->first();
        $record->status = ($record->status === 'PENDENTE') ? 'ENTREGUE' : 'PENDENTE';
        $record->save();
    } catch (EntityNotFoundException $e) {
        return Redirect::to('purchases')->with('errors', new MessageBag(array(
            "An item with the ID:$id could not be found."
        )));
    }

    return Redirect::to('purchases')->with('success', new MessageBag(array(
        'Item Atualizado'
    )));

}

public function postEdit($id) {
    //
    $record = Product::whereId($id)->first();
    $record->fill(Input::all());

    $record->save();
    return Redirect::to('products')->with('success', new MessageBag(array(
        'Item Atualizado'
    )));
}

and there is this form in view Edit:

@extends('laravel-bootstrap::layouts.interface-edit')

@section('title')
    Editar Usuário: {{ $item->name }}
@stop

@section('heading')
    <h1>Editar Usuário: <small>{{ $item->name }}</small></h1>
@stop

@section('form-items')

      {{-- The title form item --}}
    <div class="form-group">
        {{ Form::label( "title" , 'Título' , array( 'class'=>'col-lg-2 control-label' ) ) }}
        <div class="col-lg-10">
            {{ Form::text( "title" , Input::old( "title", $item->title ) , array( 'class'=>'form-control' , 'placeholder'=>'Título' ) ) }}
        </div>
    </div>

    {{-- The content form item --}}
    <div class="form-group">
        {{ Form::label( "content" , 'Conteúdo' , array( 'class'=>'col-lg-2 control-label' ) ) }}
        <div class="col-lg-10">
            {{ Form::text( "content" , Input::old( "content", $item->content ) , array( 'class'=>'form-control' , 'placeholder'=>'Conteúdo' ) ) }}
        </div>
    </div>

    {{-- The points form item --}}
    <div class="form-group">
        {{ Form::label( "points" , 'Pontos' , array( 'class'=>'col-lg-2 control-label' ) ) }}
        <div class="col-lg-10">
            {{ Form::text( "points" , Input::old( "points", $item->points ) , array( 'class'=>'form-control' , 'placeholder'=>'Pontos' ) ) }}
        </div>
    </div>

    {{-- The image form item --}}
    <div class="form-group">
        {{ Form::label( "image" , 'Imagem' , array( 'class'=>'col-lg-2 control-label' ) ) }}
        <div class="col-lg-10">
            {{ Form::text( "image" , Input::old( "image", $item->image ) , array( 'class'=>'form-control' , 'placeholder'=>'Imagem' ) ) }}
        </div>
    </div>

    {{-- The status form item --}}
    <div class="form-group">
        {{ Form::label( "ststus" , 'Status' , array( 'class'=>'col-lg-2 control-label' ) ) }}
        <div class="col-lg-10">
            <label class="radio">
                {{ Form::radio( "status" , true, $item->status) }} SIM 
            </label>
            <label class="radio">
                {{ Form::radio( "status" , false, !$item->status) }} NÃO
            </label>
        </div>
    </div>

@stop

And be Routes

Route::get('auth/logout', 'AuthController@doLogout');
Route::post('auth/login', 'AuthController@doLogin');
Route::post('auth/recuperar', 'AuthController@doRecuperar');
Route::get('admin', 'AuthController@doAdmin');
Route::post('/auth/admin/login', 'AuthController@doLoginAdmin');


// Route::controller( 'admin/products'  , 'ProductsController' );

Route::controller('users', 'UsersController', array('before' => 'adminauth'));
Route::controller('products', 'ProductsController', array('before' => 'adminauth'));
Route::controller('purchases/{sort?}', 'PurchasesController', array('before' => 'adminauth'));
Route::controller('/', 'HomeController');
  • You can post the routes of your application?

  • Routes added

  • My guess is that you just put the class name on the route - you have to put the FQDN there, which is the class name plus the namespace.

  • I’ll take a look at it, as I said is the first contact with Laravel and is to solve this problem. HEHE

  • I entered the route Route::get('purchases/edit{id}', 'PurchasesController@getEdit'); but it had no effect

  • 1

    Missing a bar in purchases/edit{id}, that would be purchases/edit/{id}. You can see the routes configured in the application with the command php artisan routes.

  • Corrected and funfou, I will post the solution as answer

Show 2 more comments

2 answers

1


This action had to be routed in /app/controllers/route.php

Route::get('purchases/edit/{id}', 'PurchasesController@getEdit');

With the inclusion of this line the error has been corrected and the functionality is perfect.

0

You could declare the route this way:

Route::controller('purchases', 'PurchasesController');

and in your controller you put the filters in the constructor method.

public function __construct() {
    $this->beforeFilter('adminauth');
}

This way the getEdit, postEdit and other routes added later in the controller would respond.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.