Middleware that allows admin ONLY to delete record in Laravel 5

Middleware that allows admin ONLY to delete record in Laravel 5

SHARE

Laravel has a cool way of filtering HTTP requests entering your application. The HTTP Middleware. You can find all your Middleware inside your ‘App\Http\Middleware‘ folder. Middleware is in charge of the default user authentication and verification filters. Like if a user is not logged in, then it will be redirected to a login screen. And so much more you can do about it.

To learn more about Middleware check the official docs here.

I will share basic filter that will only allow admin user to delete records in your app. This means that even the one who created the record, if he is not administrator, he cannot delete his own record. ( of course if you want him to delete record you can just tweak the code ).

Before we proceed:

  • If you don’t have categorization of your user role (admin, encoder, author, 1, 2 etc…),  just make sure to alter user table, add a field named ‘role’ or any identifier for your role.
Prev1 / 4

SHARE
Programmer, Database Designer and Administrator for Web Application. Who loves to read and write interesting topics.

90 COMMENTS

  1. After reading your blog post I browsed your website a bit and noticed you are not ranking nearly as well in Google as you could be. I possess a handful of blogs myself and I think you should take a look at speed rank seo, just search it on google. You will find its a very nice tool that can bring you a lot more visitors. Keep up the quality posts

  2. Hey There !! Get Viral on Twitter, Tweet your message to 1,000,000 real people. If you’re familiar with Twitter you know that you can Tweet to get GREAT exposure for your website, business, product, music, video or cause!

  3. I simply want to mention I am new to blogging and site-building and certainly savored your blog site. Likely I’m likely to bookmark your blog post . You actually come with excellent articles. Regards for sharing your web page.

  4. I was suggested this website via my cousin. I’m now not sure if this submit is written by him as
    no one else realize such specified approximately my
    trouble. You will be incredible! Thanks!

  5. I just want to say I am all new to weblog and really enjoyed your page. Likely I’m want to bookmark your website . You absolutely come with fabulous articles and reviews. Thanks a lot for revealing your web page.

  6. Hi there, I came across your blog by using Google while in search
    of a related matter, your site came up, it appears to be good.
    We have bookmarked it in my google bookmarks.
    Hello there, simply changed into aware about your blog through Google, and located
    that it is really informative. I am going to be cautious for brussels.

    I’ll be grateful should you proceed this in future.
    Many other folks will be benefited from your writing.
    Cheers!

  7. I will right away grab your rss while i can’t find your
    email subscription link or e-newsletter service. Do you have any?

    Please permit me recognise as a way that I could subscribe.
    Thanks.

  8. After exceeding a few of the blog articles in your website,
    I truly like your strategy for blogging. I added
    it to my bookmark site list and are checking back soon. Take a
    look at my website too and inform me your opinion.

  9. Excellent article. Keep writing such kind of info on your
    site. Im really impressed by it.
    Hi there, You’ve done an incredible job. I will definitely
    digg it and in my opinion suggest to my friends.

    I am confident they’ll be benefited from this website.

  10. It’s a shame you don’t possess a donate button! I’d most certainly donate to the fantastic blog!
    I suppose for the time being i’ll be happy with book-marking and adding your Feed to my Google account.
    I enjoy brand new updates and will focus on this site with my
    Facebook group. Chat soon!

  11. Hello, i feel that we saw you visited my web site
    thus i got to return the favor.I’m wanting to find points to enhance my site!I suppose its ok to make use of
    several of your thoughts!!

  12. I blog frequently and I genuinely appreciate your information. Your article has really peaked my interest.
    I will take a note of your website and keep checking for
    new information about once a week. I opted in for your RSS feed as well.

  13. After I initially left a comment I appear to have clicked the -Notify me when new comments are added- checkbox now each time
    a comment is added I recieve four emails using the same comment.
    Perhaps there exists a simple method it is possible to remove me from that service?

    Thanks!

  14. It’s a shame you don’t have a donate button! I’d undeniably donate to this particular superb blog!
    I guess for the present time i’ll be happy with bookmarking and adding your Feed to my Google account.
    I anticipate fresh updates and may share this blog with my Facebook group.
    Chat soon!

  15. Hi there, i read your blog site every now and then and i own a comparable one and i was just curious should
    you get lots of spam remarks? If exactly how do you stop it, any plugin or anything you can recommend?
    I become a whole lot lately it’s driving me insane so any help
    is extremely much appreciated.

  16. hey there and many thanks for your info – I’ve definitely found anything new
    from right here. I did however expertise several technical points by using
    this site, as I experienced to reload the website a lot of times
    previous to I could get it to load correctly. I was wondering
    should your hosting is OK? Not too I am complaining, but sluggish loading instances times will very frequently affect your placement in the search engines and can damage your quality score if advertising and marketing with Adwords.
    Well I am adding this RSS to my email and could look out for
    a lot more of your respective exciting content. Make sure you update this again very soon.

  17. Heya! I just wished to ask should you ever have trouble with hackers?
    My last blog (wordpress) was hacked and so i finished up losing many months of work because of no data backup.
    Do you possess any solutions to stop hackers?

  18. you are actually a excellent webmaster. The site loading speed is incredible.
    It seems that you’re doing any unique trick. Furthermore, The contents are
    masterpiece. you’ve performed a magnificent job on this
    matter!

  19. I’m truly experiencing the design and layout of your own website.
    It’s an extremely easy around the eyes which makes it considerably more enjoyable in my opinion to come here and visit
    more frequently. Do you hire out a designer to make your theme?
    Fantastic work!

  20. This design is spectacular! You certainly learn how to have a reader amused.
    In between your wit along with your videos, I had been almost transferred to
    start my very own blog (well, almost…HaHa!) Wonderful job.
    I really loved whatever you had to say, and more than that, the way you presented it.
    Too cool!

  21. Today, I went to the beachfront with my children. I found a sea shell and
    gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell to her ear and screamed.
    There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is entirely off topic but I had to tell someone!

  22. Hi there, just became alert to your site through Google, and located that it can be
    really informative. I’m planning to look out for brussels.

    I’ll be grateful in the event you continue this in future.

    Many individuals will be took advantage of your writing. Cheers!

  23. Howdy fantastic website! Does running a blog similar to this take a great deal of work?
    I’ve very little understanding of coding however I was hoping to start my own blog soon. Anyways,
    if you have any suggestions or tips for new blog owners
    please share. I know this is off topic but I simply had to ask.

    Kudos!

  24. naturally just like your web-site but you must check the spelling on quite
    a few of the posts. Many are rife with spelling issues and I
    find it very bothersome to tell the reality on the other hand
    I’ll surely come back again.

  25. Hey There !! Get Viral on Twitter, Tweet your message to 1,000,000 real people. If you’re familiar with Twitter you know that you can Tweet to get GREAT exposure for your website, business, product, music, video or cause!

  26. Hey I am so happy I found your website, I really found you by accident, while I was
    browsing on Digg for something else, Nonetheless I am
    here now and would just like to say many thanks for a remarkable post and a all
    round enjoyable blog (I also love the theme/design),
    I dont have time to look over it all at the moment but I have saved it
    and also included your RSS feeds, so when I have time I will be back to read a
    lot more, Please do keep up the fantastic b.

  27. Hey! This is certainly my first visit to your site!
    We have been a team of volunteers and starting a whole new project in a community
    in the same niche. Your blog provided us beneficial information to work on. You may have done a extraordinary job!

  28. Fantastic goods by you, man. I’ve keep in mind your
    stuff previous to and you’re simply extremely great.
    I really like what you have got right here, certainly like what you’re saying and
    the way in which through which you assert it. You are making it entertaining and
    you carry on and care for to stay it sensible. I cant wait to learn a lot more of your stuff.
    Which is actually a great site.

  29. I have been browsing online more than 3 hours today, but I never discovered
    any attention-grabbing article like yours. It’s beautiful price sufficient for me personally.
    Personally, if all web owners and bloggers made good content as you
    probably did, the net will most likely be far more useful
    than in the past.

  30. I’d want to many thanks for the efforts you’ve devote penning this website.
    I am hoping to find out the identical high-grade content by you later on as well.
    In reality, your creative writing abilities has encouraged me to acquire my very own, personal site now 😉

  31. I don’t know if it’s just me or if perhaps all the others encountering complications with your website.
    It seems just as if a number of the written text with your content are running away from
    the screen. Can somebody else please comment and tell me if this is happening directly to them
    also? This might be considered a problem with my browser
    because I’ve had this happen previously. Many thanks

  32. Write more, thats all I actually have to say. Literally, it appears to be as though you used the recording to help make your point.
    You clearly understand what youre talking about, why get rid of your intelligence on just posting videos
    for your site when you could be giving us something enlightening to see?

  33. Hello! Quick question that’s entirely off topic. Have you figured out how you can make your site mobile friendly?
    My website looks weird when viewing from my
    iphone. I’m trying to find a theme or plugin that could possibly correct this problem.
    For those who have any recommendations, please share.
    Cheers!

  34. Howdy! I know this is kinda off topic nevertheless I’d figured I’d ask.
    Would you be interested in trading links or maybe guest writing a blog post or vice-versa?
    My blog discusses a lot of the same subjects as yours and I feel
    we could greatly benefit from each other. If you’re
    interested feel free to shoot me an email. I look forward to hearing from you!
    Excellent blog by the way!

  35. Does your site use a contact page? I’m having problems locating it but, I’d love to shoot an email.
    I’ve got some recommendations for your personal blog you may well be
    interested in hearing. In any case, great website and I enjoy seeing it expand as
    time passes.

  36. Hello There. I stumbled upon your blog site using msn. This is certainly
    an incredibly well written article. I’ll
    make sure to bookmark it and return to learn more of your useful information.
    I appreciate you the post. I am going to definitely comeback.

  37. My partner and i also stumbled right here different page and thought I should check things out.
    I love a few things i see so i am just just following you.
    Look ahead to exceeding your online page for any second time.

  38. Thank you, I’ve recently been searching for information approximately this subject for ages and yours is the greatest I’ve discovered so far.
    But, what in regards to the conclusion? Are you positive about the source?

  39. I am just curious to find out what blog system
    you might be using? I’m experiencing some minor security issues with my latest site
    and I might want to find something more secure. Do you have any suggestions?

  40. Good day! This is kind of off topic but I need some
    advice from an established blog. Is it very difficult to set up your own blog?
    I’m not very techincal but I can figure things out pretty fast.
    I’m thinking about setting up my own but I’m not sure where to begin. Do you have any tips
    or suggestions? Many thanks

  41. You actually help it become seem really easy with the presentation however I to get this topic being really something which I feel I would
    personally never understand. It type of feels too complicated and very huge
    for me personally. I’m taking a look forward for your subsequent post, I’ll attempt to get the hold than it!

  42. Hi there do you mind letting me know which webhost you’re utilizing?
    I’ve loaded your site in 3 different browsers and I must say this
    blog loads a lot faster then most. Is it possible to recommend an effective internet hosting
    provider in a fair price? Many thanks, I appreciate it!

  43. Oh my goodness! Impressive article dude! Many thanks, However I am just encountering troubles with your RSS.

    I don’t understand the main reason why I cannot sign up for it.
    Can there be anybody else getting identical RSS issues?
    Anybody who knows the solution can you kindly respond?
    Thanks!!

  44. Perhaps you have thought about including a bit more than only your content?
    After all, what you say is important and everything.

    But think of when you added some good images or videos to give your posts more, “pop”!
    Your posts is fantastic although with pics and videos, this blog could undeniably be one
    of the very best in their niche. Really good blog!

  45. This is really interesting, You are a very skilled blogger.

    I have joined your rss feed and look forward to seeking more of your wonderful post.

    Also, I have shared your site in my social networks!

  46. I the same as the helpful info you supply in your articles.
    I’ll bookmark your blog and check out again here frequently.

    I’m somewhat certain I’ll learn lots of new stuff right here!
    Have a great time for these!

  47. Today, I went to the beach with my kids.
    I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.”
    She placed the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear.

    She never wants to go back! LoL I know this is entirely off topic
    but I had to tell someone!

LEAVE A REPLY