Created
February 9, 2019 00:49
-
-
Save tiagoandrepro/28922b044e1b35b6cb5de216a14d5a68 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; | |
use Illuminate\Support\Facades\Gate; | |
class AuthServiceProvider extends ServiceProvider | |
{ | |
/** | |
* The policy mappings for the application. | |
* | |
* @var array | |
*/ | |
protected $policies = [ | |
'App\Model' => 'App\Policies\ModelPolicy', | |
'App\Models\Post' => 'App\Policies\PostPolicy' | |
]; | |
/** | |
* Register any authentication / authorization services. | |
* | |
* @return void | |
*/ | |
public function boot() | |
{ | |
$this->registerPolicies(); | |
// | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers\User; | |
use Illuminate\Http\Request; | |
use App\Http\Controllers\Controller; | |
use App\Models\Post; | |
use App\Http\Requests\PostFormRequest; | |
use Auth; | |
use App\User; | |
class PostController extends Controller | |
{ | |
public function __construct() | |
{ | |
$this->authorizeResource(Post::class, 'Post'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Policies; | |
use App\User; | |
use App\Models\Post; | |
use Illuminate\Auth\Access\HandlesAuthorization; | |
class PostPolicy | |
{ | |
use HandlesAuthorization; | |
/** | |
* Determine whether the user can view the Post. | |
* | |
* @param \App\User $user | |
* @param \App\Models\Post $Post | |
* @return mixed | |
*/ | |
public function view(User $user, Post $Post) | |
{ | |
return $user->id === $Post->user_id; | |
} | |
/** | |
* Determine whether the user can create Posts. | |
* | |
* @param \App\User $user | |
* @return mixed | |
*/ | |
public function create(User $user) | |
{ | |
// | |
} | |
/** | |
* Determine whether the user can update the Post. | |
* | |
* @param \App\User $user | |
* @param \App\Models\Post $Post | |
* @return mixed | |
*/ | |
public function update(User $user, Post $Post) | |
{ | |
// | |
} | |
/** | |
* Determine whether the user can delete the Post. | |
* | |
* @param \App\User $user | |
* @param \App\Models\Post $Post | |
* @return mixed | |
*/ | |
public function delete(User $user, Post $Post) | |
{ | |
// | |
} | |
/** | |
* Determine whether the user can restore the Post. | |
* | |
* @param \App\User $user | |
* @param \App\Models\Post $Post | |
* @return mixed | |
*/ | |
public function restore(User $user, Post $Post) | |
{ | |
// | |
} | |
/** | |
* Determine whether the user can permanently delete the Post. | |
* | |
* @param \App\User $user | |
* @param \App\Models\Post $Post | |
* @return mixed | |
*/ | |
public function forceDelete(User $user, Post $Post) | |
{ | |
// | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Como que estão suas rotas?