Вопрос

I'm sort of a newb to Laravel 4 and Sentry 2, but i've managed to survive so far. I'm running into a problem right now, cause when im logged in as userid(1) and i want to view the profile of userid(2) i'm just seeing the information of userid(1) on the profile of userid(2).

I'm aware that using filters might come in handy at this, but if i have to be honest. I have no idea what i should look at etc.

I know this site is not meant for giving answers. But if someone could give me a bit of an answer, where to look, what i should keep in mind etc. that would be very much appreciated.

---EDIT---

Route:

Route::group(array('before'=>'auth'), function(){

    Route::get('logout', 'HomeController@logout');
    Route::get('profile/{username}', 'ProfileController@getIndex');

});

Route::filter('auth', function($route)
{
    $id = $route->getParameter('id');
    if(Sentry::check() && Sentry::getUser()->id === $id) {
        return Redirect::to('/');
    }
});

ProfileController

public function getIndex($profile_uname)
    {
        if(Sentry::getUser()->username === $profile_uname) {
            // This is your profile
            return View::make('user.profile.index');
        } else {
            // This isn't your profile but you may see it!
            return ??
        }
    }

View

@extends('layouts.userprofile')

@section('title')
    {{$user->username}}'s Profile
@stop

@section('notification')
@stop

@section('menu')
    @include('layouts.menus.homemenu')
@stop

@section('sidebar')
    @include('layouts.menus.profilemenu')
@stop

@section('content')
    <div class="col-sm-10 col-md-10 col-xs-10 col-lg-10">
        <div class="panel panel-info">
            <div class="panel-heading"><h3>{{ $user->username }}</h3></div>
        </div>
    </div>
@stop

@section('footer')
@stop
Это было полезно?

Решение

This might work for you:

<?php

public function getIndex($profile_uname)
{
    if(Sentry::getUser()->username === $profile_uname) {
        // This is your profile
        return View::make('user.profile.index');
    } else {
        // This isn't your profile but you may see it!
        return View::make('user.profile.index')->with('user', Sentry::findUserByLogin($profile_uname));
    }
}

If username is not your login column, then you can do it in two steps:

$userId = \Cartalyst\Sentry\Users\Eloquent\User::where('username', $profile_uname)->first()->id;

return View::make('user.profile.index')->with('user', Sentry::findUserById($userId));

If you have a User model tied to your users table, you can just do:

$userId = User::where('username', $profile_uname)->first()->id;

return View::make('user.profile.index')->with('user', Sentry::findUserById($userId));

And in this last case you probably will be able to use that same model, since they would be the same in Sentry and pure Eloquent:

$user = User::where('username', $profile_uname)->first();

return View::make('user.profile.index')->with('user', $user);

Also, to avoid a conflict between your views related to the current logged user, you should rename the $user variable you are instantiating via View::share() or View::composer() from $user to $loggedUser or something like that.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top