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

HomeControler fails if using table prefix #50

Closed
dany-eudes opened this issue Feb 17, 2015 · 3 comments
Closed

HomeControler fails if using table prefix #50

dany-eudes opened this issue Feb 17, 2015 · 3 comments

Comments

@dany-eudes
Copy link

Some raw sql strings in HomeControler.php will fail if using a table prefix configuration in config/database.php.

The following code will fix that:

public function index()
{
        $tbpfx = DB::getTablePrefix();

        $news = $this->news->orderBy('position', 'DESC')->orderBy('created_at', 'DESC')->limit(4)->get();
        $sliders = Photo::join('photo_album', 'photo_album.id','=','photo.photo_album_id')
                        ->where('photo.slider',1)
                        ->orderBy('photo.position', 'DESC')
                        ->orderBy('photo.created_at', 'DESC')
                        ->select('photo.filename','photo.name','photo.description','photo_album.folderid')->get();

        $photoalbums = PhotoAlbum::select(array('photo_album.id', 'photo_album.name', 'photo_album.description',
                'photo_album.folderid',
                                                DB::raw("(select filename from ${tbpfx}photo as p WHERE album_cover=1 and p.photo_album_id=${tbpfx}photo_album.id) AS album_image"),
                                                DB::raw("(select filename from ${tbpfx}photo as p WHERE p.photo_album_id=${tbpfx}photo_album.id ORDER BY position ASC, id ASC LIMIT 1) AS album_image_first")))->limit(8)->get();

        $videoalbums = VideoAlbum::select(array('video_album.id', 'video_album.name', 'video_album.description',
                'video_album.folderid',
                                                DB::raw("(select youtube from ${tbpfx}video as v WHERE album_cover=1 and v.video_album_id=${tbpfx}video_album.id) AS album_image"),
                                                DB::raw("(select youtube from ${tbpfx}video as v WHERE v.video_album_id=${tbpfx}video_album.id ORDER BY position ASC, id ASC LIMIT 1) AS album_image_first")))->limit(8)->get();

        return view('site.home.index',compact('news','sliders','videoalbums','photoalbums'));
 }

I don't check others but that's it!

Many thanks for this repository.

@stojankukrika
Copy link
Collaborator

THX 👍

@dany-eudes
Copy link
Author

I guess you forgot the first code line: $tbpfx = DB::getTablePrefix(); in your commit, isn't it?
Best regards!

@stojankukrika
Copy link
Collaborator

yea. I didn't see that, and I am rush. TNX.
Best regards!

@zcosmin20 zcosmin20 mentioned this issue Dec 1, 2015
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

No branches or pull requests

2 participants