Thank you so much for the tips, this really help me in my current project, before I used to created multiple api resources , but now I can replace with only one which save a lot of time and work. Thank you I really appreciate. watching your videos everyday from Nigeria 👍
Nice! What I usually do, is in the controller add some param in the request, so then in the resource I know what to do, and create the return array from there. I think that it should be interesting if Laravel allows to send more data in the resource, it's very limited
I think adding a param is a better approach, because you separate the concerns. The resource doesn't need to know what route is making the request, just let the controller take care of it...
Sir, is there any similar options with FormRequests validations? For example we have an Alarm API, where all users table has timezone column with some timezone value (UTC+3). In the resource of alarm(s) we transform all data to the user’s timezone. But when the user sends post request to API to create an alarm at 2022-07-20 09:00:00, in FormRequest we have to: 1) validate time value is filled (required) 2) validate time value has correct date time format 3) if everything is ok - transform all data to UTC and go ahead to the Alarms controller.
Validation should happen in Form Requests classes. But transformation of the data should happen with accessors/mutators in the model. An older video from me with a similar example: ruclips.net/video/WsD5QvLn4is/видео.html
I like the videos about API resources. Now that laravel goes more into SPA (at least that's how I see it) Livewire, replacement of webpack with vite, APIs becoming more interesting and important. But that's just my prediction where Laravel wants to go.
Thanks for your video. I have a question: when you used "$this->when" I expected the value of description to be empty, instead even the key disappear in Postman. Can you explain me why? What am I missing? Thanks.
I know this is not related to today's video but allow me to drop it here. I'm building an e-commerce system and would like to integrate a product recommendation engine. Apart from creating the model in python and interacting with it using APIs, is there a "Laravel-ish" way of doing this?
In this case an example would be, when one navigates to a product there's a tab with "similar product" In the case of working, not products of the same category entirely, but based on user behavior or interests or based on other users who viewed that product interest
Exactly, every logic and algorithm is different and unique, so it's hard to answer your question for all possible projects. A simple recommendation engine could be just one DB query selecting items by same tags. More complex could involve a huge graph of data.
Thanks. I found out there's a package that does what I was talking about which utilizes "The Recombee recommendation engine " API, sends the data to racombee engine, the engine prepares and runs the model and then you can get predictions from your model
Thanks for the video. I learnt a lot from your videos. Can you please tell me where to store large static data in laravel so that we can use in multiple places. I am storing them directly in blade template as array inside @php . But Its very repitative. (Please make a video on this topic if possible)
@@LaravelDaily Thanks for replying. Here is my situation - I am building a website for a travel agency and I have some blog style text and images for 10 different locations . I have to show these data in multiple pages. They don't want to store the data in database and they won't update or edit these data. They also has some static data for their contact and other information. I want to store these data in one place so that I can manage them in future easily.
Thank you so much for the tips, this really help me in my current project, before I used to created multiple api resources , but now I can replace with only one which save a lot of time and work.
Thank you I really appreciate. watching your videos everyday from Nigeria 👍
Nice! What I usually do, is in the controller add some param in the request, so then in the resource I know what to do, and create the return array from there. I think that it should be interesting if Laravel allows to send more data in the resource, it's very limited
I think adding a param is a better approach, because you separate the concerns. The resource doesn't need to know what route is making the request, just let the controller take care of it...
Thank you for this. First time I'm seeing the $this->when in the resource
You can do also ternary operator in the key of array or if else conditions to add a new element in array
Sir, is there any similar options with FormRequests validations? For example we have an Alarm API, where all users table has timezone column with some timezone value (UTC+3). In the resource of alarm(s) we transform all data to the user’s timezone. But when the user sends post request to API to create an alarm at 2022-07-20 09:00:00, in FormRequest we have to:
1) validate time value is filled (required)
2) validate time value has correct date time format
3) if everything is ok - transform all data to UTC and go ahead to the Alarms controller.
Validation should happen in Form Requests classes. But transformation of the data should happen with accessors/mutators in the model. An older video from me with a similar example: ruclips.net/video/WsD5QvLn4is/видео.html
I like the videos about API resources. Now that laravel goes more into SPA (at least that's how I see it) Livewire, replacement of webpack with vite, APIs becoming more interesting and important. But that's just my prediction where Laravel wants to go.
I tried this way to conditional rendering for relationships, and whenLoaded method doesnt work as expected and I had to use different resources
Is it okay to send message and status from API controller?
Yes if you prefer to do so
Thanks for your video. I have a question: when you used "$this->when" I expected the value of description to be empty, instead even the key disappear in Postman. Can you explain me why? What am I missing? Thanks.
No, that's how when works. Please read the docs of Laravel.
$this->when returns a `MissingValue` class instead of null, so inside Laravel just deletes fields with value of the `MissingValue` class.
@@ИгорьСорокин-й3ж Ahhhh ok, that's what I was missing! Thanks!
In description you don't paste link to your newsletter.
It should be in the list of all links at the end of description.
To separate a list of objects from single object i use ResourceCollection instead of JsonResource.
I know this is not related to today's video but allow me to drop it here. I'm building an e-commerce system and would like to integrate a product recommendation engine. Apart from creating the model in python and interacting with it using APIs, is there a "Laravel-ish" way of doing this?
Not enough information, "product recommendation engine" may mean a dozen of things and how exactly it should work
In this case an example would be, when one navigates to a product there's a tab with "similar product"
In the case of working, not products of the same category entirely, but based on user behavior or interests or based on other users who viewed that product interest
Exactly, every logic and algorithm is different and unique, so it's hard to answer your question for all possible projects. A simple recommendation engine could be just one DB query selecting items by same tags. More complex could involve a huge graph of data.
Thanks. I found out there's a package that does what I was talking about which utilizes "The Recombee recommendation engine " API, sends the data to racombee engine, the engine prepares and runs the model and then you can get predictions from your model
what is the purpose of putting the routeIs condition in the isWhen as the logic is dont in the callback? could you just put nothing in here?
Awesome, thank u so much
Thanks for the video. I learnt a lot from your videos. Can you please tell me where to store large static data in laravel so that we can use in multiple places. I am storing them directly in blade template as array inside @php . But Its very repitative. (Please make a video on this topic if possible)
Store as array in config file. If you give more exact example I can answer in more details
@@LaravelDaily Thanks for replying. Here is my situation - I am building a website for a travel agency and I have some blog style text and images for 10 different locations . I have to show these data in multiple pages. They don't want to store the data in database and they won't update or edit these data. They also has some static data for their contact and other information. I want to store these data in one place so that I can manage them in future easily.
If it's only for YOU to manage, then yes, create config/staticpages.php file with array and then load config(staticpages.keys) wherever you need
@@LaravelDaily Yes it's only for me. Thanks a lot 🙏
I think in this case we could have used match experssion.
👍👍👍👍👍
Thanks
can you make all of your course available on udemy?
So udemy would sell my courses cheaper and also take more than 50% of my money? No, thanks, I will stay at laraveldaily.teachable.com :)
👏👏👏
thats a good approach but you're kinda turning it into a graphql api LOL