How should I serve an image with Laravel?

Viewed 56678

I'm storing user profile pictures in laravel storage folder instead of the public folder because I would like to keep the public folder clean from user clutter.

In order to serve an image from that folder, I created a simple Controller Action as follows:

public function profilePicture($person, $size = 40){
    $profile_picture_url = storage_path().'/profile_pictures/'.$person['id'].'/profile_'.$size.'.jpg';

    if(!File::exists( $profile_picture_url ))
        App::abort(404);

    return Image::make($profile_picture_url)->response('jpg');
}

Can this be considered a good practice, or should I simply save pictures in the public folder? Will I run into performance issues by doing so?

4 Answers
Related