PHP 7/8 Syntax in Laravel: Do You Use it?

PHP 7/8 Syntax in Laravel: Do You Use it?

Laravel Daily

3 года назад

11,331 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@sergeygabrielyan5021
@sergeygabrielyan5021 - 20.07.2021 11:06

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
];
}
}

Ответить
@ShowcasewebdevelopmentCoUk
@ShowcasewebdevelopmentCoUk - 12.05.2021 11:35

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?

Ответить
@taghwomills6310
@taghwomills6310 - 03.05.2021 15:15

Union types is great since mixed can’t be used for type hunting method arguments

Ответить
@JeanGomesPereira
@JeanGomesPereira - 29.04.2021 15:22

Do you have articles too? I prefer reading text than watching videos.

Ответить
@MartinBojmaliev
@MartinBojmaliev - 27.04.2021 01:31

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

Ответить
@code_blizz
@code_blizz - 23.04.2021 15:31

Please sir, what is the reason why Auth::login($user); is not working? can you explain

Ответить
@VadimBesedin
@VadimBesedin - 22.04.2021 12:05

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?

Ответить
@NathanBudd
@NathanBudd - 21.04.2021 19:23

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?

Ответить
@VonBismarkOtto
@VonBismarkOtto - 21.04.2021 17:47

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

Ответить
@thelostrider1
@thelostrider1 - 21.04.2021 14:40

Is (?int $projectID) the same as (int $projectID = null)?
And, how do you know when something should be type strict or not?

Ответить
@neerajsinghtangariya2587
@neerajsinghtangariya2587 - 21.04.2021 13:01

Sir is there any difference between `is_null` or `empty` ?

Ответить
@user-bq9yy3bt9k
@user-bq9yy3bt9k - 21.04.2021 08:54

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

Ответить
@thansurya
@thansurya - 21.04.2021 07:16

Colud u please do videos about multi seller concept?

Ответить
@jonhycdv
@jonhycdv - 21.04.2021 05:19

Maybe instead of returning false or null, you could have just returned an empty collection.

Ответить
@itz_edrisa
@itz_edrisa - 21.04.2021 02:42

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?

Ответить
@FranckMercado
@FranckMercado - 21.04.2021 02:18

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.

Ответить
@alila3883
@alila3883 - 21.04.2021 01:11

I agree.

Ответить
@MustafaBirsoz
@MustafaBirsoz - 20.04.2021 23:00

Thanks bro

Ответить
@ControlAltSuprimir
@ControlAltSuprimir - 20.04.2021 22:56

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?

Ответить
@leonardoldr
@leonardoldr - 20.04.2021 21:56

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.

Ответить
@karlebh
@karlebh - 20.04.2021 18:15

Interesting. I would like to see more of this.

Ответить
@JohnnyBigodes
@JohnnyBigodes - 20.04.2021 17:28

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

Ответить
@cvija997
@cvija997 - 20.04.2021 16:11

Can you make blog post comments logic? I think its a bit confusing and i would love to see your way of doing it.

Ответить
@Voltra_
@Voltra_ - 20.04.2021 14:28

shift+F6 for renaming variables in PHPStorm ;)

Ответить
@haithembenghorbal3991
@haithembenghorbal3991 - 20.04.2021 13:36

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 :)

Ответить
@bartlomiej-bak
@bartlomiej-bak - 20.04.2021 12:43

I guess 'union types' are a workaround to implement polymorphism in PHP.

Ответить
@programmingisanotherworld3989
@programmingisanotherworld3989 - 20.04.2021 12:27

Hi Povilas, Thanks a lot, can you please keep doing videos like this? Showing new Php features? Thanks again!

Ответить
@mohamed1gohar
@mohamed1gohar - 20.04.2021 12:04

Thank you on this video ... I want know your color style used on IDE

Ответить
@turkialharbi9234
@turkialharbi9234 - 20.04.2021 11:23

What is the best way to filter products by brands without using any framework please 🙏

Ответить
@midnightlead
@midnightlead - 20.04.2021 11:01

In the real life we have editing old code and use old packages.

Ответить
@bhupendra-mistry
@bhupendra-mistry - 20.04.2021 10:51

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.

Ответить
@othmantabati3757
@othmantabati3757 - 20.04.2021 10:47

Can you make a video about how to optimize mysql queries on large databases using indexes ?

Ответить
@konstantin5437
@konstantin5437 - 20.04.2021 10:38

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"?

Ответить
@atatopatato
@atatopatato - 20.04.2021 10:37

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

Ответить
@lparede
@lparede - 20.04.2021 10:01

You've read my mind! Thank you!

Ответить
@Jurigag
@Jurigag - 20.04.2021 09:30

Of course, it's like our core things, we always use it with declare(strict_types = 1); We have all properties, methods typehinted.

Ответить
@tannercampbell
@tannercampbell - 20.04.2021 08:56

I think when returning collection from eloquent model it should be the other one. Illuminate\Database\Eloquent\Collection

Ответить
@L-A-O-S
@L-A-O-S - 20.04.2021 08:55

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.

Ответить
@andrii.adventure
@andrii.adventure - 20.04.2021 08:36

Constructor property promotion is also great feature in PHP 8.

BTW I recommend use “refactor” feature in PHPStorm instead of manually renaming variables:)

Ответить
@PouyaKhadem
@PouyaKhadem - 20.04.2021 08:35

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.

Ответить
@RichardTippin
@RichardTippin - 20.04.2021 08:35

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.

Ответить
@o2b3k
@o2b3k - 20.04.2021 08:16

Great

Ответить
@vitouvitou5269
@vitouvitou5269 - 20.04.2021 08:12

Thanks teacher

Ответить
@DevPasjaByDanielSmigiela
@DevPasjaByDanielSmigiela - 20.04.2021 08:09

first! greetings from poland, again :)

Ответить