How to make sure a user can only delete his own records using Laravel -
how make sure user can delete own records.
here how deleting post following url.
now user can pass post id here , record deleted id regardless if post not belong user. how can overcome issue using laravel
the best way use policies purpose
policies classes organize authorization logic around particular model or resource. example, if application blog, may have
post
model , correspondingpostpolicy
authorize user actions suchcreating
orupdating
posts.
if reason don't want use policies, can check user manually:
if (auth()->check && auth()->user()->id === $post->user_id) { // delete post. }
Comments
Post a Comment