towhid's avatar

next previous profile in single profile view

scenario : i have a result set for 20 profile , if i click then single profile view show . now i want to next profile and previews profile view button . when i click next button then go next profile in my result set collection by descending wise data .

i don't understand how to get next id and previews id in my profile view blade , please help me . thank you

if any kind of quarry please ask me - then i will discuss details .

as like i have contact list when i click then show 4 record descending wise . if i click one contact profile then show one single page , and now i want to next profile view out of 4 descending wise . so how to to ? that ?

i have contact profile controller where i collect my contact list collection , and my user profile controller for single profile view page .. . and other things i have many kind of record set for difference type of record collection .

so how to do and what the procedure in laravel for next previous profile view

1 like
8 replies
towhid's avatar

Yes its Work its 100 Work :) thanks my big brother :) , but i have one another question which one i share with you

other things i have many kind of record set for difference type of record collection .

how to centrally this ? or every record collection depend s on every difference quarry for this single profile view - like

1# my contact list some record list collection 2# my proposal list record list collection 3# my search list record list collection 4# [one important thing i ave many type of search form which one get collect data and through different different search pagination ] - so whats i do ? centrally dynamic quarry or single single different type of quarry for all single profile view page .

thank you @tisuchi

1 like
tisuchi's avatar

@towhid

As of now, I can think for two ways-

  1. If possible fetch via relationship. For example, establish relationships between different collections.

  2. You may add a common wrapper for every collection. For example-

$contacts = Contact::get();
$proposals = Proposal::get();

$contacts->map(function($contact){
    $data['title'] = '';
    $data['name'] = $contact->name;
    $data['details'] = '';
    $data['phone'] = $contact->phone;
    ....
    ...
});


$proposals->map(function($propsal){
    $data['title'] = $propsal->title;
    $data['name'] = '';
    $data['details'] = $prospal->details;
    $data['phone'] = '';
    ....
    ...
});

I just gave you a rough idea of how to address the issue. Ofcourse, you may need to tweak a lot on it.

2 likes
towhid's avatar

@tisuchi Hi , This is my problem scenario :

i have one controller name userprofile controller here i call method name index() and this is my single profile view controller

this is my single profile route

Route::get('user/user-profile-view/{id}', 'User\UserprofileController@index');

i have many kind of record set - like .

contact list # proposal list # favorite list # trash list #all user list # active user list

so when record list show then click single profile view button . when action button click

 <a href="{{ url('user/user-profile-view',$userInfo->user_id) }}">

there are many different type record set for click single view profile ...

in this moment i want this previous and next record .

its good news i follow your instruction and complete next previous issue . but new thing is , how to do for all kind of different different type record set from different different controller .

now i am direct call all variable from userprofile controller

that's why arise new issue if i have record set for one quarry contact list controller then my previous and next data show ... but if some one try to another single page from other controller like favorite controller then show

Trying to get property 'id' of non-object

this is my quarry

 $userID =  ContactRequest::where('contact_receiver_user_id', $id)->where('mode', 1)->where('contact_request.contact_sender_user_id', auth()->user()->id)->select('id')->first()->id;

        //    dd($userID);

        $next = ContactRequest::join('user_infos', 'user_infos.user_id', 'contact_request.contact_receiver_user_id')
            ->where('contact_request.contact_sender_user_id', auth()->user()->id)
            ->whereIn('contact_request.contact_receiver_user_id', [DB::raw("SELECT id FROM active_users_id")])
            ->where('mode', 1)
            ->where('contact_request.id', '<', $userID)
            ->orderBy('contact_request.contact_date', 'desc')
            ->first();



        $previous = ContactRequest::join('user_infos', 'user_infos.user_id', 'contact_request.contact_receiver_user_id')
            ->where('contact_request.contact_sender_user_id', auth()->user()->id)
            ->whereIn('contact_request.contact_receiver_user_id', [DB::raw("SELECT id FROM active_users_id")])
            ->where('mode', 1)
            ->where('contact_request.id', '>', $userID)
            ->orderBy('contact_request.contact_date', 'desc')
            ->first();

        // dd($previous);

        $first = ContactRequest::join('user_infos', 'user_infos.user_id', 'contact_request.contact_receiver_user_id')
            ->where('contact_request.contact_sender_user_id', auth()->user()->id)
            ->whereIn('contact_request.contact_receiver_user_id', [DB::raw("SELECT id FROM active_users_id")])
            ->where('mode', 1)
            ->orderBy('contact_request.contact_date', 'desc')
            ->first();

        $last = ContactRequest::join('user_infos', 'user_infos.user_id', 'contact_request.contact_receiver_user_id')
            ->where('contact_request.contact_sender_user_id', auth()->user()->id)
            ->whereIn('contact_request.contact_receiver_user_id', [DB::raw("SELECT id FROM active_users_id")])
            ->where('mode', 1)
            ->orderBy('contact_request.contact_date', 'desc')
            ->get()
            ->last();


its error for this code

 $userID =  ContactRequest::where('contact_receiver_user_id', $id)->where('mode', 1)->where('contact_request.contact_sender_user_id', auth()->user()->id)->select('id')->first()->id;

how to condition use for this quarry ?

or do you have others way to solve this kind problem-

this is my blade next previous action button

  <ul class="pagination pull-right profile_pag">
@if($first->contact_receiver_user_id != $id)
<li>
 <a class="btn btn-circle btn-xs" href="{{url('user/user-profile-view',$first->contact_receiver_user_id)}}">
<i class="fa fa-angle-left"></i> First
 </a>
</li>
@endif
@if(!empty($previous->contact_receiver_user_id))
<li>
<a class="btn btn-circle btn-xs" href="{{url('user/user-profile-view',$previous->contact_receiver_user_id)}}">
<i class="fa fa-angle-left"></i> Prev
</a>
</li>
@endif
@if(!empty($next->contact_receiver_user_id))
<li>
<a class="btn btn-circle btn-xs" href="{{url('user/user-profile-view',$next->contact_receiver_user_id)}}">
 Next<i class="fa fa-angle-right"></i>
</a>
</li>
  @endif
  @if($last->contact_receiver_user_id != $id)
 <li>
 <a class="btn btn-circle btn-xs" href="{{url('user/user-profile-view',$last->contact_receiver_user_id)}}">
 <i class="fa fa-angle-right"></i> Last
 </a>
</li>
  @endif
 </ul>

thank you

1 like
tisuchi's avatar

@towhid

I try to digest your points, but I feel your application architecture is somehow complex.

I suggest you make your application structure as simple as possible. May be classified responsibilities, tasks and depends on relationships. So that you can easily fetch and render data.

2 likes
towhid's avatar

yes , i know brother . but what can i do my exiting project running this application architecture plan . i just followed existed.

but what i do now ? record set how to keep my single profile view - ? please read my problem again if you help m some thing then really help my Task . in this laracasts video tutorial has no video in this topics . (record set view with previews next ) and centrally variable collect difference difference - controller

1 like
tisuchi's avatar

@towhid

Yeah, of course, you can use a custom helper function. Nothing wrong to use custom helper function in that case.

The uses of custom helper functions are when there is some common data that will be used in many places. It will be advisable to make sure that, there is not N+1 issue for that.

2 likes

Please or to participate in this conversation.