thank you so much for this. i was able to use the observer to update the comment count in the post table every time a new comment was added. i am really learning a lot from you... i hope you will continue doing this tutorial videos.. you are a gift to all of us.
Sir I am a great fan of your teaching laravel and always wait for your next o ne video......Very few peoples are like you......Could you make a video on Jwt authentication for api in laravel..
Using Laravel 5.7, this isn't working when creating a new user. The seeding part works but I get "no default value for api_token" error when saving a new user.
Hi what if i have multilevel authentications like [ Users - Admins - Sellers ] etc , How could i manage the tokens and do you have a way to do that with JWY or Passport ? Thanks in Advance :)
Thanks for awesome job u are doing sir. Please i asked a question on your previous laravel series but it has not been answered. (series 33). I love to add anchor tag on my categories so that when people click it, it loads posts under each category. I planned to launch my app by 17th of this month and this is the only functionality that remains
thank's for your help but i have a problem when i try to access in a page protect by auth:api with my vuejs function ($http ) it return this error 401 (Unauthorized) i'd like to redirect it to login page if user is a guest thank's a lot
Where you are using axios through Laravel, I thought you didnt need api tokens as the request is validated through the auth middleware and session. Is there a reason why this wouldnt be secure?
Hi Sir, First of all, a great thank for you amazing video that did, it’s really useful. I have a question about a Rest API, I will tell you what I am planning to do I have main application build with Laravel, it’s the main have all the data, and also have clients I want to install small application in their local server also build by laravel, to work locally and no need for internet access. What I am planning to do, is to make the client application talk with main application and fetch all the updated data, and the client application sends some data to the main application. As I know OAuth2 is the best way to make secure channel between two applications, if you have some video you made, and it may help me, please kindly share it with me. Or you may help by some advice. (I already try to do it, but I got some problem and error and I am not sure if I am using the right way to do it)
I wanted to authenticate api with api_token and I have multiple auth system with different role. The api should only be accessed by admin group and selected role admin. For that I have done as follows in ApiController public function __construct() { $this->middleware('auth:admin'); // for admin authentication $this->middleware('superadmins'); //only superadmins role can access api } API url are all fine but i get error with above two lines. It says {"error":"unauthenticated."} But if i remove those middleware it works fine without authentication Note: I haven't used laratrust, all middleware are created manually
For me, random is something like dice. Sometimes you have luck and you hit 6,6,6. If this happened in observer, i think the creating of user will stop and a error will be thrown. Am I right?
What is the difference between observers and events? We can fire an even when ever we are creating, deleteing, etc or created, deleted, etc by using the dispatchesEvents protected variable inside the model
Observers are "lower level". They won't be queued (like normally events would be) and they have DIRECT ACCESS to the model you are working with. Events are good for triggering things to happen like sending an email or a notification, but they arent good for directly manipulating the model, which is what we needed here. While you can trigger events at the "creating" state, the model doesn't wait around for the event and all of its listeners to complete. It simply triggers the event and keeps moving. The observer on the other hand is designed to directly manipulate the model. So it jumps in and runs its process and actually holds up the save() function while it works. So by targeting the "creating" stage, we know that the observer is going to be able to finish its job before the model continues the save process. So each has its own purpose. If i wanted to send a welcome email whenever a new user is added to the database, then creating an event tied to the "created" event would be the smarter way to do it. You wouldn't want to use observers for that task because 1) you want that process to be queued and observers can't be queued, and 2) you don't want the model to continue waiting on the observer to finish sending the email. So emails and notifications are great for events because they don't need direct access to the model (only a copy of it) and they can happen asynchronous of the event's save procedure. Observers are better for directly manipulating the model like we do in this video because we do want to hold up the save procedure until we generate that new api_token and we want it run synchronous to the save procedure. I have a video on using events to send a welcome email whenever a user is "created", if you want to see how you would do that: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-YHW5YzmA9_E.html
I have the same problem. But when i put $user->api_token = bin2hex(openssl_random_pseudo_bytes(30)); in store on controller, it´s work. I´m confused now!