This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.
Here is my Code but its not working..................
$modelMusicCurrent = modelMusicCurrent::whereNotNull('published')
->where('published', '=', 1)
->where('is_trending', '=', 1)
->where('is_deleted', '=', 0)
->get();
$modelEntertainmentCelebritiesCurrent = modelEntertainmentCelebritiesCurrent::whereNotNull('published')->union($modelMusicCurrent)->get();
$modelEntertainmentMoviesCurrent = modelEntertainmentMoviesCurrent::whereNotNull('published') ->union($modelEntertainmentCelebritiesCurrent );
$modelEntertainmentStyleCurrent = modelEntertainmentStyleCurrent::whereNotNull('ddpublished')->union($modelEntertainmentMoviesCurrent);
$modelEntertainmentStyleCurrent ->orderBy($this->property('orderBy', 'created_at'), 'desc')
->skip($this->property('skipItems', 0))
->take($this->property('maxItems', 6))
->get()
If you used ->get(), you cant use UNION after that. It already returns a collection. What you are looking for is merge() probably.
<?php
$modelMusicCurrent = modelMusicCurrent::whereNotNull('published')
->where('published', '=', 1)
->where('is_trending', '=', 1)
->where('is_deleted', '=', 0)
->get();
$modelEntertainmentCelebritiesCurrent = modelEntertainmentCelebritiesCurrent::whereNotNull('published')->get();
$modelMusicCurrent->merge($modelEntertainmentCelebritiesCurrent);
// Merge the others as well...
oh sorry i have not used get() above. I do not want to use merge ..since it will not let to get required result.
I want to combine all table results using UNION and then to set orderBY and Limit as like this.
return $qry_result = DB::select(DB::raw("select * from
(
(select `id`,`name`,`alias`, concat('music_currents','') as `type`, created_at from akhil_vh1_music_currents where `published` = 1 AND `is_trending` = 1 AND `is_deleted` = 0)
union
(select `id`,`name`,`alias`, concat('entertainment_celebrities_currents','') as `type`,created_at from akhil_vh1_entertainment_celebrities_currents where `published` = 1 AND `is_trending` = 1 AND `is_deleted` = 0)
union
(select `id`,`name`,`alias`, concat('entertainment_style_currents','') as `type`,created_at from akhil_vh1_entertainment_style_currents where `published` = 1 AND `is_trending` = 1 AND `is_deleted` = 0)
ORDER BY created_at DESC
) Qry LIMIT :vskip , :vlimit ") , array('vskip'=>$num1,'vlimit'=>$num2)
);
But problem with the above code is i am not able to get images from system files that why i want to use OctoberCMS standard model structure to get attachment image .
I have some wht sorted the union issue.........but not able to implement Oder by and Limit on whole output. Any IDEA for OrderBY and LIMIT for whole union output?
$modelMusicCurrent = modelMusicCurrent::select('id','name','alias')
->whereNotNull('published')
->where('published', '=', 1)
->where('is_trending', '=', 1)
->where('is_deleted', '=', 0);
$modelEntertainmentCelebritiesCurrent = modelEntertainmentCelebritiesCurrent::select('id','name','alias')
->whereNotNull('published')
->where('published', '=', 1)
->where('is_trending', '=', 1)
->where('sis_deleted', '=', 0);//->get('id','name','alias')
$modelEntertainmentStyleCurrent = modelEntertainmentStyleCurrent::select('id','name','alias')
->whereNotNull('published')
->where('published', '=', 1)
->where('is_trending', '=', 1)
->where('iss_deleted', '=', 0)
->union($modelMusicCurrent->getQuery())
->union($modelEntertainmentCelebritiesCurrent->getQuery())
->orderBy('created_at', 'desc')
->skip(0)
->take(6)
->get('id','name','alias');
Last updated
Separate point, you shouldn't need ->whereNotNull('published')
if your'e also looking for ->where('published', '=', 1)
as that will ignore any results that are null or not 1 anyway
Last updated
laravel/framework [Bug] Unable to limit and order unions #4758 https://github.com/laravel/framework/pull/4758
1-6 of 6