Support the ongoing development of →
posted 8 years ago
Last updated 4 months ago.

Could you put how did you obtain the resource data from your Model and how did you make accesible in the view?

Last updated 4 months ago.
class Tagstours extends Eloquent {

	protected $connection = 'letsgo'; // static 
    protected $table = 'tours_tags';
	protected $primaryKey = 'id';
	public $timestamps = false;

	//public $restful = true;
	// Check for Online status
	public function scopeApproved($query){
		$query->where('tours.status', 1);
	// By Name
	public function scopeByname($tours, $orderby) {
		$tours->orderBy('tours.title_long_' . strtoupper(LaravelLocalization::getCurrentLanguage()), $orderby);
	// By Days
	public function scopeBydays($tours, $orderby) {
		$tours->orderBy('tours.days', $orderby);
	// By Category Tags
	public function scopeTags($tours, $variable) {

		$results = $tours->whereIn('tours_tags.tags_id', explode(" ", $variable));


$tours = Tagstours::join('tours', '', '=', 'tours_tags.tours_id')
					' AS id', 
					'tours.urlid AS urlid', 
					'tours.title_long_' . $language,
					'tours.title_' . $language,
					'tours.details_' . $language,
					'tours.info_' . $language,
					'tours.days AS days', 
					'tours.participants_' . $language,
					'tours.skill_' . $language,
					'tours.season_' . $language,
					'tours.image AS image', 
				->distinct('tours_tags.tours_id', '')
			$totalrows = Tagstours::join('tours', '', '=', 'tours_tags.tours_id')

			switch ($order_first) {
				case 'name':
				$tours = $tours->byname($orderby);
				case 'days':
				$tours = $tours->bydays($orderby);
			$tours = $tours->approved()->paginate($offset);
			$pagination_links = $tours->appends(array('order' => Input::get('order'), 'tags' => Input::get('tags')))->links();
Last updated 4 months ago.

I am having this issue has this issue been resolved?

I am using Laravel 5

My issue is this:

Searching for all movies with a string like "%die har%"

There are lots of movies with this string (55 title match this string) Only 18 unique(distinct id's) Movie id's.

otherMovieTitles::select( DB::raw('DISTINCT(id)') )->where('title', 'LIKE', '%'.$search.'%')->paginate(10);

Does anyone have a way to get around this.

Example of this issue is on the below URL:

If I use groupBy('id') it doesn't allow the paginate to work at all.



Today I found a way around this issues by using the built in LengthAwarePaginator in Laravel 5. The down size to this is that if you use this as the paginator it just displays all the data rather than just the 10 that you want.

This is only a part solution as I say.This is why I have to use bother lengthaware and normal pagination.


use Illuminate\Pagination\Paginator;
use Illuminate\Pagination\LengthAwarePaginator;
class SearchController extends MovieController {
    public function getMoviesView()
         $total = 10;
         $allmovies = otherMovieTitles::select( DB::raw('DISTINCT(id)') )->where('title', 'LIKE', '%'.$search.'%')->get();
         $movies = otherMovieTitles::select( DB::raw('DISTINCT(id)') )->where('title', 'LIKE', '%'.$search.'%')->paginate($total);
         if(Null !== Paginator::resolveCurrentPage())
            $paginationOption = ['path'=>'movies'];
        } else {
            $paginationOption = ['path'=>'search/movies'];
        $paginator =  new LengthAwarePaginator($allmovies, count($allmovies), $total, Paginator::resolveCurrentPage(),$paginationOption);
        return view('', compact('movies', 'search', 'paginator'));// Show the page


<li class="active"><a href="{{URL::to('search/movies?search='.$search)}}">Movie {{$paginator->total()}}</a></li>
@foreach ($movies as $movie )
... Display movie data
<div class="list">
   {!! $paginator->appends(array('search' => $search)))->render() !!}

If anyone finds a way to solve the issue with displaying all the data rather than a limited amount, please do let me know.

Hope this helps people.


Last updated 7 years ago.

If you folks would search the forum you would have seen there's already a detailed post on this. Really, search first.


Sign in to participate in this thread!


Your banner here too?

goranata goranata Joined 12 Mar 2014


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2022 - All rights reserved.