Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help] Image does not get written to file system #51

Closed
spaceemotion opened this issue Apr 5, 2014 · 7 comments
Closed

[Help] Image does not get written to file system #51

spaceemotion opened this issue Apr 5, 2014 · 7 comments

Comments

@spaceemotion
Copy link

Well, here we go again: I have yet another file system issue.

I am using Stapler in two cases: For the Avatar changing and for the user galleries. When I upload an avatar and save my profile the file gets uploaded and processed like it should. I am using the below code for this:

    public function update()
    {
        $user = Confide::user();
        $user->nickname = Input::get('nickname');
        $user->about = Input::get('about');

        $avatarFile = Input::file('avatar');

        if($avatarFile !== null)
        {
            $user->avatar = $avatarFile;
        }

        if(!$user->updateUniques()) {
            Notification::danger($user->errors()->all());
        }

        return Redirect::action('user.profile', $user->getPresenter()->id);
    }

For the galleries it's somehow not working. I don't quite know why, but it somehow stopped working - for absolutely no reasons, I did not change anything on the webserver nor the upload code. I am using the following code for the picture uploads:

    public function upload($hashId)
    {
        try {
            $gallery = Gallery::findOrFail($this->getId($hashId));

            $picture = new Picture;
            $picture->picture = Input::file('file');
            $picture->gallery()->associate($gallery);

            if ($picture->save())
            {
                return Response::json($picture->toArray(), 200);
            }

            return Response::make('Could not upload image', 500);

        } catch (ModelNotFoundException $ex) {
            return Response::make('Gallery does not exist', 500);
        }
    }

When the avatar saves it also creates all the needed subfolders. When the picture gets uploaded it doesn't create the folders. I already checked, and yes indeed, I do have the right permissions set: drwxrwxrwx 1 vagrant vagrant.

Why has this code somehow stopped working? I haven't updates stapler either ... It's a mystery to me.

@spaceemotion
Copy link
Author

Any ideas? I really need this working within the next few days, otherwise I would have to try to write my own thing, which I would like to avoid!

@oguchy
Copy link

oguchy commented Apr 23, 2014

Hi.
I had a similar issue and (maybe) solved it.

How about Picture::boot() ?

'Stapler' trait has boot() method (only calling static::bootStapler() method.) and registers some model events in it.
So you should call bootStapler() static method explicitly in your Model::boot() method if you are overriding it.

@tabennett
Copy link
Contributor

What @x46k said is true; if you've overridden the static boot method of your model then you're going to have to make a call to static::bootStapler() somewhere within that method. Take a look at this: #61

@spaceemotion
Copy link
Author

Hmmm, I'm using Ardent. Might that be the issue?

@rossedman
Copy link

I am having the same problem. Ardent is overwriting the boot method and then Confide is extending Ardent and then User class is extending that. However, if after updating the boot method I am still having problems.

Every figure this out? Here is my code added to the User model:

public static function boot()
 {
    parent::boot();
    static::bootStapler();
 }

@karlshea
Copy link

I think the issue is that the Stapler EloquentTrait shouldn't have a boot() method in it at all.

I was having the same issue on models that I was adding in global scopes in the boot() method, but since I was also using the EloquentTrait that method wasn't ever getting called since the model was directly overriding it.

If you remove the boot() function from Codesleeve\Stapler\ORM\EloquentTrait and replace it with this everything works fine:

/**
 * The "booting" method of the model.
 */
public static function bootEloquentTrait()
{
    static::bootStapler();
}

I'm going to open a pull request with this change, I'm guessing others have run into the issue.

@tabennett
Copy link
Contributor

This has been implemented in the upcoming 2.0 release (currently on the dev branch).

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

Successfully merging a pull request may close this issue.

5 participants