ログインユーザーは、自分の投稿や他のものが表示されている他のユーザーのプロフィールページに移動できます。他のユーザーのプロフィールに移動する(laravel 5.2)
は、私が試したことは以下の通りである:
私のルート:
Route::get('/myplace/{username}' , [
'uses' => '[email protected]' ,
'as' => 'myplace' ,
'middleware' => 'auth:web'
]);
のPostController:
public function getmyplace($username)
{
$user = User::where('username', $username)->first();
if(!$user)
abort(404);
$posts=Post::where(function($query){
$query->where('user_id',Auth::user()->id)
->orWhereIn('user_id',Auth::user()->friends()->lists('id')
);
})
->orderBy('created_at','desc')->get();
$accounts=Account::orderBy('updated_at','desc')->limit(1)->get();
return view('myplace',['user'=>$user,'posts'=>$posts,'accounts'=>$accounts]);
}
私の見解:
> @if (!$posts->count())
> <p>{{$user->getNameOrUsername() }} hasn't posted anything, yet.</p>
> @else
> @foreach ($posts as $post)
> @if(Auth::user()== $post->user)
>
> <div class="panel panel-default">
> <div class="panel-heading">
> <div class="row">
> <section class="col-md-2 col-xs-2"> <img id="imagesize2" src="images/g.jpg" class="img-circle" data-action="zoom"/></img>
> </section> <section class="col-md-5 col-xs-offset-1 col-xs-5">
> <a id="alink13" href=""><h5
> id="alink14">{{$post->user->getNameOrUsername() }}</h5></a>
> <p> on {{$post->created_at}} </p> </section>
> </div>
> <div class="panel-content">
> <div class="row" id="fetch">
> <section class="col-md-12" data-postid="{{ $post->id }}">
> <p id="post">{{$post->body}}</p>
> <div class="interaction" >
> @if(Auth::user()==$post->user)
> <a href="" class="edit">Edit</a>
> <a id="remove2" href="{{route('post.delete',['post_id' => $post->id])}}">Delete</a>
> @endif
> </div>
> </section>
> </div>
> </div>
私はusernameパラメータを渡されたが、それはなかった所望の出力を得た。
私が提供する必要があるものは何でも教えてください。
どのようなエラーが発生しますか?あなたが手に入れたいものと手に入れたものは何ですか? –
@AmirBar私は誰かのプロフィールに行くと、そのユーザーのコンテンツ(ここでは投稿)が表示されます。私は何を得ているのですか?>ログインしたユーザの内容は次のとおりです –