Skip to content

Instantly share code, notes, and snippets.

@tiagoandrepro
Created February 9, 2019 00:49
Show Gist options
  • Save tiagoandrepro/28922b044e1b35b6cb5de216a14d5a68 to your computer and use it in GitHub Desktop.
Save tiagoandrepro/28922b044e1b35b6cb5de216a14d5a68 to your computer and use it in GitHub Desktop.
<?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();
//
}
}
<?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');
}
<?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)
{
//
}
}
@edbizarro
Copy link

Como que estão suas rotas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment