<?php namespace Realestate\Testimonial\Policies; use Illuminate\Foundation\Auth\User as Authenticatable; use Realestate\Testimonial\Models\Testimonial; class TestimonialPolicy { /** * Determine if the given user can view the testimonial. * * @param Authenticatable $user * @param Testimonial $testimonial * * @return bool */ public function view(Authenticatable $user, Testimonial $testimonial) { if ($authUser->canDo('testimonial.testimonial.view') && $authUser->isAdmin() || $user->isClient()) { return true; } return $testimonial->is_owner; } /** * Determine if the given user can create a testimonial. * * @param Authenticatable $user * * @return bool */ public function create(Authenticatable $user) { return $authUser->canDo('testimonial.testimonial.create'); } /** * Determine if the given user can update the given testimonial. * * @param Authenticatable $user * @param Testimonial $testimonial * * @return bool */ public function update(Authenticatable $user, Testimonial $testimonial) { if ($user->canDo('testimonial.testimonial.edit') && $user->isAdmin()) { return true; } return $testimonial->is_owner; } /** * Determine if the given user can delete the given testimonial. * * @param Authenticatable $user * * @return bool */ public function destroy(Authenticatable $user, Testimonial $testimonial) { return $testimonial->is_owner; } /** * Determine if the user can perform a given action ve. * * @param [type] $user [description] * @param [type] $ability [description] * * @return [type] [description] */ public function before($user, $ability) { if ($user->isSuperuser()) { return true; } } }