我正在使用此Controller来获得用户对项目的许可
public function show($id)
{
if (Permission::where('status', 1)->where('project_id', $id)->exists()) {
// if((Permission::where('status', '=', '1')->first()) && (Permission::where('project_id','=',$id)->first())){
$project = Project::find($id);
$tasks = $this->getTasks($id);
$files = $this->getFiles($id);
$comments = $this->getComments($id);
$collaborators = $this->getCollaborators($id);
$permissions = $this->getPermissions($id);
returnview('collaborators.show')->withProject($project)->withTasks($tasks)->withFiles($files)->withComments($comments)->withCollaborators($collaborators);
}
else if
//return('hi');
(Permission::where('status', 2)->where('project_id', $id)->exists()) {
$project = Project::find($id);
$tasks = $this->getTasks($id);
$files = $this->getFiles($id);
$comments = $this->getComments($id);
$collaborators = $this->getCollaborators($id);
$permissions = $this->getPermissions($id);
return view('collaborators.manager')->withProject($project)->withTasks($tasks)->withFiles($files)->withComments($comments)->withCollaborators($collaborators);
}
我的权限模型是
<?php
namespace App;
use Auth;
use Illuminate\Database\Eloquent\Model;
class Permission extends Model
{
protected $table = 'permissions';
protected $fillable = ['status','project_id','collaborator_id'];
public function scopeProject($query, $id)
{
return $query->where('project_id', $id);
}
public function scopeProjectp($query, $cid)
{
return $query->where('collaborator_id', $cid);
}
public function scopePermissioneditt($query, $id, $projectId)
{
return $query->where('collaborator_id',$id)->where('project_id',$projectId);//->exists();
}
public function scopeProjectac($query)
{
return $query->where('collaborator_id', Auth::user()->id);
}
/* public static function permission($collaboratorId, $projectId)
{
return Permission::where('collaborator_id', $collaboratorId)->where('project_id', $projectId);
}*/
public function user()
{
return $this->belongsTo(User::class, 'collaborator_id');
}
/* public function project()
{
return $this->belongsToMany('App\Project');
}*/
public function project_collaborator()
{
return $this->belongsToMany('App\Collaboration','collaborator_id');
}
//
}
我需要根据当前用户Auth :: user-&gt; id检查和访问权限表;给予许可用户。