仅显示用户自己的通知 Laravel
Show only the notifications of the user self Laravel
我做了一个网站,你可以在那里做报告,你必须用你的帐户提交表格,然后管理员可以处理该报告,这样用户就可以登录并查看报告和状态它,但我希望用户只能看到他自己的报告而不是其他人?
这是我的 html
@extends('layouts.app')
@section('content')
<div class="container">
<div class="mTop">
<div class="row justify-content-center">
<div class="col-md-8">
@if(session('message'))
<div class="alert alert-success" role="alert">
{{session('message')}}
</div>
@endif
<div class="card">
<div class="card-header">Retourmeldingen</div>
<div class="card-body">
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Firmanaam</th>
<th scope="col"></th>
<th scope="col"></th>
<th scope="col">Status</th>
<th scope="col">Verwerkingstijd</th>
<th scope="col"></th>
</tr>
</thead>
@foreach($retours as $retour)
<tbody>
<tr>
<th scope="row">{{ $retour->firmaname }}</th>
<td><a href="{{ route('return.show', $retour->id) }}">
<button type="button" class="btn btn-secondary btn-sm m-0">Bekijk
</button>
</a></td>
<td>@if( $retour->status === 0)
<a href="{{ route('return.edit', $retour->id) }}">
<button type="button" class="btn btn-secondary btn-sm m-0">Wijzig
</button>
</a>
@else
<a href="{{ route('return.edit', $retour->id) }}">
<button type="button" class="btn btn-secondary btn-sm m-0" disabled>
Wijzig
</button>
</a>
@endif
</td>
<td>@if( $retour->status === 0)
Open
@else
<i style="color: #05af00; font-size: 25px"
class="fa fa-check-circle"></i>
@endif</td>
<td>
@if($retour->status === 0)
Nog niet verwerkt
@elseif($retour->diffInDays === 0)
Zelfde dag verwerkt
@elseif( $retour->diffInDays === 1)
{{ $retour->diffInDays }} dag
@elseif( $retour->diffInDays >= 1)
{{ $retour->diffInDays }} dagen
@endif
</td>
<td>
<form method="post"
action="{{ route('return.destroy', $retour->id) }}">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger btn-sm m-0"><i
class="fa fa-trash" aria-hidden="true"></i>
</button>
</form>
</td>
</tr>
</tbody>
@endforeach
</table>
</div>
</div>
<div class="mt-3">{{ $retours->links() }}</div>
</div>
</div>
</div>
</div>
@endsection
所以我想要的是用户根据公司名称只能看到他自己的报告,我现在的是你可以看到所有的报告
在我看来,您应该在控制器级别应用过滤器,返回以仅查看顾问用户拥有的报告集合。
这应该通过报告中的 user_id
字段来完成 table 如果任何报告属于一个唯一用户,或者一个数据透视表 table 如果一个报告可以有多个所有者。
因此,如果报告仅属于唯一用户,您应该在 sql 查询中通过 WHERE 语句进行过滤,例如:
$reports = Reports::where('user_id', $auth->user()->id)->where('other conditions')->get();
然后,在您看来,您将只有属于当前用户的报告,这也解决了安全问题。
我做了一个网站,你可以在那里做报告,你必须用你的帐户提交表格,然后管理员可以处理该报告,这样用户就可以登录并查看报告和状态它,但我希望用户只能看到他自己的报告而不是其他人? 这是我的 html
@extends('layouts.app')
@section('content')
<div class="container">
<div class="mTop">
<div class="row justify-content-center">
<div class="col-md-8">
@if(session('message'))
<div class="alert alert-success" role="alert">
{{session('message')}}
</div>
@endif
<div class="card">
<div class="card-header">Retourmeldingen</div>
<div class="card-body">
<table class="table table-hover">
<thead>
<tr>
<th scope="col">Firmanaam</th>
<th scope="col"></th>
<th scope="col"></th>
<th scope="col">Status</th>
<th scope="col">Verwerkingstijd</th>
<th scope="col"></th>
</tr>
</thead>
@foreach($retours as $retour)
<tbody>
<tr>
<th scope="row">{{ $retour->firmaname }}</th>
<td><a href="{{ route('return.show', $retour->id) }}">
<button type="button" class="btn btn-secondary btn-sm m-0">Bekijk
</button>
</a></td>
<td>@if( $retour->status === 0)
<a href="{{ route('return.edit', $retour->id) }}">
<button type="button" class="btn btn-secondary btn-sm m-0">Wijzig
</button>
</a>
@else
<a href="{{ route('return.edit', $retour->id) }}">
<button type="button" class="btn btn-secondary btn-sm m-0" disabled>
Wijzig
</button>
</a>
@endif
</td>
<td>@if( $retour->status === 0)
Open
@else
<i style="color: #05af00; font-size: 25px"
class="fa fa-check-circle"></i>
@endif</td>
<td>
@if($retour->status === 0)
Nog niet verwerkt
@elseif($retour->diffInDays === 0)
Zelfde dag verwerkt
@elseif( $retour->diffInDays === 1)
{{ $retour->diffInDays }} dag
@elseif( $retour->diffInDays >= 1)
{{ $retour->diffInDays }} dagen
@endif
</td>
<td>
<form method="post"
action="{{ route('return.destroy', $retour->id) }}">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger btn-sm m-0"><i
class="fa fa-trash" aria-hidden="true"></i>
</button>
</form>
</td>
</tr>
</tbody>
@endforeach
</table>
</div>
</div>
<div class="mt-3">{{ $retours->links() }}</div>
</div>
</div>
</div>
</div>
@endsection
所以我想要的是用户根据公司名称只能看到他自己的报告,我现在的是你可以看到所有的报告
在我看来,您应该在控制器级别应用过滤器,返回以仅查看顾问用户拥有的报告集合。
这应该通过报告中的 user_id
字段来完成 table 如果任何报告属于一个唯一用户,或者一个数据透视表 table 如果一个报告可以有多个所有者。
因此,如果报告仅属于唯一用户,您应该在 sql 查询中通过 WHERE 语句进行过滤,例如:
$reports = Reports::where('user_id', $auth->user()->id)->where('other conditions')->get();
然后,在您看来,您将只有属于当前用户的报告,这也解决了安全问题。