我正在尝试编辑用户的帖子,并限制用户仅编辑他们创建的帖子。 (我在本教程中提到了:Traversy Media的https://www.youtube.com/watch?v=PAP8IS_ak6w&t=12s)
这是我到目前为止所得到的:
HTML
@if (count($posts) > 0)
<table class="table">
<tbody>
@foreach($posts as $post)
<tr>
<td width="80%">{{ $post->title }}</td>
<td class="display-inline-flex">
<a href="{{ url('/posts') }}/{{$post->id}}/edit">Edit</a>
{!!Form::open(['action' => ['PostsController@destroy', $post->id], 'method' => 'POST', 'style' => 'margin: 0px 20px;'])!!}
{{Form::hidden('_method', 'DELETE')}}
{{Form::submit('Delete', ['class' => 'btn-link btn-delete'])}}
{!!Form::close()!!}
</td>
</tr>
@endforeach
</tbody>
</table>
@else
<p>You have no post yet!</p>
@endif
** ROUTE **
// Posts
Route::resource('posts', 'PostsController');
Auth::routes();
**控制器**
public function edit($id)
{
$post = Post::find($id);
//check for correct user
if (auth()->user()->id !== $post->user_id) {
return redirect('/posts')->with('error', 'Unauthorized page');
}
return view('posts.edit')->with('post', $post);
}
当我在本地主机上测试编辑功能时,它运行良好。但是当我上传项目并在我的服务器上测试它时,它总是重定向到Unauthorized page
。
请帮助我跟踪我的发展。
提前感谢!
答案 0 :(得分:0)
您可以使用class CustomBehavior : CoordinatorLayout.Behavior<FloatingActionButton> {
....
override fun onAttachedToLayoutParams(params: CoordinatorLayout.LayoutParams) {
super.onAttachedToLayoutParams(params)
//set dodgeInsetEdges to BOTTOM so that we dodge any Snackbars
params.dodgeInsetEdges = Gravity.BOTTOM
}
.....
}
的{{1}}吗?供参考https://laravel.com/docs/5.6/authorization
示例:https://code.tutsplus.com/tutorials/gates-and-policies-in-laravel--cms-29780