I am facing problem regarding permission
Argument 1 passed to App\Providers\AuthServiceProvider::App\Providers{closure}() must be an instance of App\Providers\User, instance of App\User given, called in C:\xampp\htdocs\Tweety\vendor\laravel\framework\src\Illuminate\Auth\Access\Gate.php on line 473 (View: C:\xampp\htdocs\Tweety\resources\views\tweet.blade.php)
I am just working to show delete button only on those tweets made by the authenticated users
my controller
public function destroy(Tweet $tweet)
{
$tweet->delete();
Session::flash('success');
return redirect()->route('tweets.index')->with(['message' => 'Tweet Deleted']);
}
my user model
public function tweets()
{
return $this->hasMany(Tweet::class)->latest();
}
my blade
@can('delete',$tweet)
<form action="{{ route('tweets.destroy',$tweet->id) }}" method="POST">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
@endcan
AuthServiceProvider
public function boot()
{
$this->registerPolicies();
Gate::define('delete', function (User $user , Tweet $tweet){
return $tweet->user->is($user);
});
}
Any help will be appreciated
AuthServiceProvider
, did you import User class correctly? looks like it's namespace issue.use App\User
– CrazyDevAuthServiceProvider
– CrazyDev