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.

http://example.com/dashboard/sessions/delete/{id}

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 , corresponding postpolicy authorize user actions such creating or updating posts.

if reason don't want use policies, can check user manually:

if (auth()->check && auth()->user()->id === $post->user_id) {     // delete post. } 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -