Skip to content
This repository has been archived by the owner on Jul 16, 2023. It is now read-only.

undefined method Illuminate\Support\MessageBag::getResults() #36

Closed
BeingTomGreen opened this issue Mar 28, 2013 · 8 comments
Closed

undefined method Illuminate\Support\MessageBag::getResults() #36

BeingTomGreen opened this issue Mar 28, 2013 · 8 comments

Comments

@BeingTomGreen
Copy link

Model:

<?php namespace Simple\Blog\Models;

use LaravelBook\Ardent\Ardent;

class Post extends Ardent
{
    //Table name
    protected $table = 'posts';

    public $autoHydrateEntityFromInput = true;

    public static $rules = array(
        'reference' => 'required|numeric',
    );

    public function author()
    {
        return $this->belongsTo('Simple\User\Models\User', 'author_id');
    }

    public function category()
    {
        return $this->belongsTo('Simple\Blog\Models\Category', 'category_id');
    }
}
?>

Controller:

  public function update($id)
  {
    //Grab the Blog post
    $post = Post::where('id', '=', $id)->first();

    //Blog Post validates and updates ok
    if ($post->save())
    {
      return Redirect::action('Simple\Blog\Controllers\AdminController@index')
        ->with('message-type', 'success')
        ->with('message-content', 'Successfully updated '. Input::get('reference') .'!')
      ;
    }
    //Blog Post failed to validate..
    else
    {
      return Redirect::action(
        'Simple\Blog\Controllers\AdminController@edit', array($id))
        ->withInput()
        ->withErrors($post->errors)
      ;
    }
  }

I get this when my input fails validation:

FatalErrorException: Error: Call to undefined method Illuminate\Support\MessageBag::getResults() in /path/to/laravel/bootstrap/compiled.php line 9186

Line 9186:

public function getAttribute($key)
{
...
$relations = $this->{$key}()->getResults();
...
}

If everything validates it carries on to the list page, although it doesn't actually update the row...

Thoughts? Something to do the fact that I am using it from within a package?

@laravelbook
Copy link
Collaborator

@BeingTomGreen I guess this is a Laravel core framework issue. I wasn't able to reproduce your scenario, but I did get an exception on Illuminate\Cookie\CookieServiceProvider.php. Expect to experience breakages from time to time since L4 is in active development. I'm sure these will get sorted out by the core team soon!

I'm closing this issue since it's not directly related to Ardent. Please feel free to post your updates.

@BeingTomGreen
Copy link
Author

I would argue it is a Ardent Issues.

Calling Validator works fine in the main app or in a package, but passing it through Ardent fails. I will update when Beta 4 is released later on today (according to Taylor).

@laravelbook
Copy link
Collaborator

@BeingTomGreen Thanks for the update. I wasn't able to reproduce the error - perhaps I didn't replicate your project structure properly. I'd like to investigate this further. Would it be possible to share the project source code... if that's not an option perhaps you could whip up a small demo project?

@laravelbook laravelbook reopened this Mar 30, 2013
@BeingTomGreen
Copy link
Author

I have removed Ardent from the current project (until we can get it working).

I will try and knock up a quick example later on today.

@mr4torr
Copy link

mr4torr commented Apr 13, 2013

@BeingTomGreen - @laravelbook I had the same problem and found the reason for the error when displaying error of validation has to be placed
$post->errors() and not $post->error as @BeingTomGreen placed.

Sorry I am to brazil and I do not know english very well, I just let my contribution.

@dustinlyons
Copy link

@laravelbook @BeingTomGreen I encountered the same error in bootstrap/compiled.php running tests. In a different environment (Ubuntu 13.04) I consistently receive this error:

....PHP Fatal error:  Call to undefined method Illuminate\Support\MessageBag::getResults() in /media/sf_repos/compass/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 1856

We're removing Ardent from our project for now. I may get some time to put this through a debugger over the next few days.

@dustinlyons
Copy link

My problems were actually related to a bug in the factory-muff project. When Ardent failed to save() due to validation errors, factory-muff was accessing an invalid class attribute before throwing its exception.

I've proposed a fix for that here: thephpleague/factory-muffin#7

@igorsantos07
Copy link
Member

I'm closing this issue now since looks like @mailontorres found the solution earlier.

Additionally, besides using errors() one can also use the public property validationErrors.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants