๐จโ๐ป Laravel Tip | chopStart() & chopEnd()
Starting from v11.13.0, two new string helper functions are now available:
1. `Str::chopStart` - Delete the given string(s) if it exists at the start.
2. `Str::chopEnd` - Delete the given string(s) if it exists at the end.
#laravel
๐จโ๐ป Laravel Tip | New artisan commands
There are new 4 artisan commands in Laravel 11:
1. `make:class`
2. `make:enum`
3. `make:interface`
4. `make:trait`
#laravel
๐จโ๐ป Laravel Tip | Context
Beginning with Laravel 11, we can now use `Context`.
It is an excellent feature that allows us to enter information, then retrieve and use that information throughout the entire request.
#laravel
๐จโ๐ป PHP Tip | Attributes
Starting from PHP 8, we can now use "Attributes". This gives us the ability to add metadata information on our class, methods, etc.
The built-in/predefined attributes are documented at: https://t.co/vPbb3WhpZr
๐จโ๐ป PHP Tip | Typed class constants
Starting from PHP 8.3, we can declare a type for constants.
When a class constant is declared with a type, the type cannot be changed by any subclasses or implementations (if the typed class constant is declared in an interface).
#php
๐จโ๐ป PHP Tip | Omit parentheses when creating an instance of class
If a class doesn't have a constructor or if the constructor doesn't require any arguments, we can simply delete the parentheses.
Deleting the parentheses can make the code cleaner and concise.
#php
๐จโ๐ป PHP Tip | Dynamic class instantiation
When creating an instance of a class, we can use a variable to hold its name.
This can allows us to determine the specific class to be instantiated during the execution of the program rather than having it hard-coded.
#php
๐จโ๐ป PHP Tip | Use `var_export`
We primarily use the `var_dump` function to output information about a variable.
But if we want to output a human-readable representation of the variable, we can use `var_export`. This function also returns a valid PHP code!
#php
๐จโ๐ป PHP Tip | Passing by Reference
Have you ever wondered why the variable you passed in a closure doesn't change as expected?
Maybe you aren't passing the variable by reference to a closure properly.
#php
๐จโ๐ป Laravel Migration | `datetimes`
We can create the creation & update columns using the `timestamps` method.
But what if we want to create the column type as datetime? Not timestamp?
It's not mentioned in the docs but we can use the `datetimes` method for this!
#laravel
๐ PHP Trivia | Scope Resolution Operator
This operator is simply known as the "double colon" (::).
Did you know that it's also called "Paamayim Nekudotayim"?
Paamayim Nekudotayim? What's the meaning of this word? It's the Hebrew word for "double colon"!
#php
๐จโ๐ป PHP | `stdClass`
This is a generic empty class, not a base class. It's the result of typecasting to object & running some built-in functions like `json_decode`, etc.
Some use cases:
- alternative to associative array
- create an anonymous class with dynamic properties
#php
๐ @laravelphp `about` Artisan Command
If you want to take a look at your application's basic information, you can use Laravel's `about` Artisan command.
This command can be helpful if you want to make sure that everything is configured correctly.
@PovilasKorop I think one of the reasons is due to Laravel's excellent ecosystem. Some of the most critical tasks in an application can be done natively without the use of third-party packages. The docs are excellent as well.
.dev is gaining popularity as a TLD for developer/tech-related websites. In the context of web dev, some are already using it: https://t.co/yKEwx0QE2M, https://t.co/6U819nJsgl, https://t.co/oks5CqkNLC
Do you think some of the big-names in web dev will also take this approach?