Skip to content

Tag: laravel

Get request for the policies in controller constructor

I’m setting up policies for my laravel application, and I’m stuck with a problem. I have to put the policy in the constructor of my controller this way: Problem is, for the store action, I have to check one of the params sent in the request to check if the user is allowed to post on the related pa…

REST convention when transforming data

I use Laravel as a REST API service for uploading and storing books. The book service follows the standard REST convention: GET: /api/books and /api/books/<book_id> for retrieving book(s) PUT: /api/books/<book_id> for updating a book POST: /api/books for adding a new book DELETE: /api/books/<bo…

Laravel create custom exception with parameters & return as JSON

I want to throw a custom exception if the variable is null and return it as JSON. I’ve tried like this: Controller Custom Exception But when I am trying to test it using postman, the return I got is not the same as I wrote in NullException. It becomes like this: Answer In your case you are returning the…

How to make unlimited category json listing?

I want to get unlimited json loop with category parent_id but I couldn’t find how to do that. Do while I searched but. I couldn’t find the source. How can I do the foreach loop do while? Can you guide me on this? Json result; Laravel code; Answer A recursive map operation seems perfect for this si…