Support the ongoing development of Laravel.io →
posted 8 years ago
Eloquent
Last updated 4 months ago.
0

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.
0
MODEL:
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));
		
	}

VIEW

$tours = Tagstours::join('tours', 'tours.id', '=', 'tours_tags.tours_id')
				->select(array(
					//DB::raw('DISTINCT(tours.id)'),
					DB::raw('DISTINCT(tours_tags.tours_id)'), 
					'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', 'tours.id')
				->tags(Input::get('tags'));
				
			$totalrows = Tagstours::join('tours', 'tours.id', '=', 'tours_tags.tours_id')
				->tags(Input::get('tags'))
				->distinct('tours_tags.tours_id')
				->approved()
				->count('tours_tags.tours_id');

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

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:

http://newtester.mymoviefinder.com/search?search=die+har&m...

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

Crazydc.

0

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.

Model

....
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('site.search.view_movieresults', compact('movies', 'search', 'paginator'));// Show the page
    }
...
}

View

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

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.

Crazydc.

Last updated 7 years ago.
0

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

0

Sign in to participate in this thread!

LoadForge

Your banner here too?

goranata goranata Joined 12 Mar 2014

Moderators

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 Laravel.io - All rights reserved.