Комментарии:
Hello, I want to know, is it possible to give type hinting to roles and permissions separately?
public function getRoles(): array
{
if (Gate::allows('role_access')) {
$roles = Role::with('permissions')->orderBy('id', 'DESC')->get();
$permissions = Permission::all();
return [
'roles' => $roles,
'permissions' => $permissions
];
}
}
Povilas, you touched on throwing exceptions as you have done many times before. It would be fantastic if you were able to do a specific video on the dos and donts / best practices for exception handling - particularly in Livewire?
ОтветитьUnion types is great since mixed can’t be used for type hunting method arguments
ОтветитьDo you have articles too? I prefer reading text than watching videos.
ОтветитьHow can we handle model inheritance properly?
For example, we have a User, and AdminUser that extends User. AdminUser holds additional data. How can we do this using OOP principles? Thank you
Please sir, what is the reason why Auth::login($user); is not working? can you explain
ОтветитьWhat's the role or functionality of the promise?
Is it just a hint of what will be returned as a result or something more?
How roes it work when defining what the method is returning, if it includes a Try/Catch for example? If it throws an exception, is that an issue vs returning a collection?
ОтветитьHell. Please don't recommend to pass any data arguments via constructor. That makes service stateful and disallow to reuse of them. Data should be passed via params of methods . Use constructor only for dependencies and configuration
ОтветитьIs (?int $projectID) the same as (int $projectID = null)?
And, how do you know when something should be type strict or not?
Sir is there any difference between `is_null` or `empty` ?
Ответитьmulti type return is some time unavoidable. ie - controller method returning data or excel file with that data - so return type will be JsonResponse|BinaryFileResponse
ОтветитьColud u please do videos about multi seller concept?
ОтветитьMaybe instead of returning false or null, you could have just returned an empty collection.
ОтветитьHi guyz..
I am creating an application for my organization and i am thinking how to properly represent a User that own a Department (Admin User for that department) and also that same User as a Staff of that Department
I have models like User, Department, Assignment
For the ownership (Admin User)
User -> hasMany(Departments, owner_id)
Department -> belongsTo(User)
For the assignment, I used a table (assignments) that has user_id, department_id also i was thinking of using department_id on user_data table..
Any suggestions to an older video that talked about this?
More than correct/incorrect I think it's responsible to document our code and using this php 7-8 features for type hint is super useful and makes it easier to debug hidden issues.
ОтветитьI agree.
ОтветитьThanks bro
ОтветитьI love your videos, last 6 months you've helped me a lot to be honest. I'm very grateful.
BTW, what do you use to record your videos?
The only thing about Union Types that I enoyed, is the ability to type-hint all kind of array variables, since we can have, Collections, any Arrayable interface and the native array type. A simple helper or method that can iterate something to call a method and perform operations with the data can be very overwhelmed by the many different "array" types.
ОтветитьInteresting. I would like to see more of this.
ОтветитьJust one tip from me... When you need a constructor you dont need to type "pubf"... Just type "__const" and you can have really quick a constructor.
On union type I have to disagree with you. The int|float is a great one when you have a function that is returning a price. The number 3 ist an int but 3.14 is a float.
That is perfectly normal when you dont have your prices as cent in the DB.
Other than that, your videos are a daily for me and I enjoy them all.
Thank you
Can you make blog post comments logic? I think its a bit confusing and i would love to see your way of doing it.
Ответитьshift+F6 for renaming variables in PHPStorm ;)
ОтветитьThanks for you videos! They are always super clear and easy to understand!
I would love to see a video about database transactions and concurrent requests.
It might be not related to Laravel specifically, but I lately had to explain some other developers why they had duplicate entries in database in case of concurrent requests, even if they were using transactions.
Talking about transaction isolation level might be too much, but explaining why we might have duplicate entries, and how to handle this situation might help a lot of people :)
I guess 'union types' are a workaround to implement polymorphism in PHP.
ОтветитьHi Povilas, Thanks a lot, can you please keep doing videos like this? Showing new Php features? Thanks again!
ОтветитьThank you on this video ... I want know your color style used on IDE
ОтветитьWhat is the best way to filter products by brands without using any framework please 🙏
ОтветитьIn the real life we have editing old code and use old packages.
ОтветитьFor variable name projectId you type hinted to int in function but it only work if you kept the id as route parameter binding if in future route parameter binding is changed from id to other field i.e. slug etc. Then we need to change the code base. If we type hinted to Project model than it work irrespective of which value is used for route model binding.
ОтветитьCan you make a video about how to optimize mysql queries on large databases using indexes ?
ОтветитьHello! doesn't one actually then also set something like "public function __construct(int projectId) with the contstructor or does one no longer need this because one uses "typed properties"?
ОтветитьI always type hint everything. It helps my IDE too because it knows the type of variable and i can use auto complete features. You can also eliminate the annotations so u get even less lines per file
ОтветитьYou've read my mind! Thank you!
ОтветитьOf course, it's like our core things, we always use it with declare(strict_types = 1); We have all properties, methods typehinted.
ОтветитьI think when returning collection from eloquent model it should be the other one. Illuminate\Database\Eloquent\Collection
ОтветитьHello, I stuck with another problem, I have a buy product button, wich on click checks balance, create order and put to product is_bought = True. But i found some security issue, if i press this button quickly (several times in one second) it pass every time balance validation, and buy this product each time(but one product can be bought one time))(controler took time for work, becouse it also connects others api), looks like the first request didn't finished, but script already works with second request, It can bring a lot of problems. I read about pessimistic lock (->lockForUpdate()), but in Lara docs not to much about it and nothing understend. Plz make video how to buy product coretcly, without security issues.
ОтветитьConstructor property promotion is also great feature in PHP 8.
BTW I recommend use “refactor” feature in PHPStorm instead of manually renaming variables:)
I've started using this syntax since last year. It's a great way to comment the code for future readings like you said. The projects I'm working on are still on PHP 7.4, so I haven't had the chance to explore PHP 8 syntax yet.
ОтветитьGreat video, definitely something I stick by. I also found that another great reason to be strict about return types: By their nature they will break the code execution, allowing me to find bugs I had otherwise overlooked when I setup testing. Small things like the wrong json resource being returned as a default value, to an empty string instead of null.
ОтветитьGreat
ОтветитьThanks teacher
Ответитьfirst! greetings from poland, again :)
Ответить