docker run --rm \
-u "$(id -u):$(id -g)" \
-v $(pwd):/var/www/html \
-w /var/www/html \
laravelsail/php82-composer:latest \
composer install
to install composer with sail on fresh pulled repository\
- configure .env
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=sail
DB_PASSWORD=password
- start sail up
- migartions, key generation
- sail npm install, then run dev
/var/www/html/ - in both paths
sail php -r "{code}"
- PHP command
> sail artisan sail:install pgsql
will add into docker-compose.yml additional postgresql service, but it can be outdated, so modify to new one manually and don't afraid to change docker-compose
\Illuminate\Support\Facades\Storage::put('test.txt', print_r($paymentsResponse->isAuthorised(), true));
but this approach saves telescope sql queries also. So in this case it is better to use:
DB::listen(fn ($query) =>
file_put_contents(
storage_path().'/logs/backbone_sync_products_sql.log',
"\n $query->sql. Bindings: ". implode(',', $query->bindings),
FILE_APPEND | LOCK_EX)
);
- Make sure your CLI interpreter is configured
- Plugin's: Project Settings
- Make sure to select right interpreter
New Laravel Way. Should be before SQL query
DB::listen(fn ($query) => file_put_contents(storage_path() . '/logs/db.log', "\n{$query->sql}", FILE_APPEND | LOCK_EX));
Old Laravel way.
\DB::enableQueryLog();
// Here lives SQL queries.
foreach (DB::getQueryLog() as $queryArray) {
file_put_contents(storage_path() . '/logs/db2.log', "\n".$queryArray['query'], FILE_APPEND | LOCK_EX);
}
dd(\DB::getQueryLog());
$table->foreignId('type_id')->nullable()->default(null)->constrained('folder_types');
- public $bindings prop in a ServiceProvider , connect interface (key of an array) with a concreate class (value of an array)
- Observers are classes that allow you to listen for certain events that happen to your models, such as creating, updating, deleting, or saving records
- Listeners: Usually, a listener is a class that handles a single event. You register the listener for a specific event in the EventServiceProvider.
Subscribers: A subscriber, on the other hand, is a class that can subscribe to multiple events and define the corresponding event handling methods. It allows you to group related event handling logic together in a single class. - Route->middleware('can:smthing.create') - can is a default Laravel middleware
https://laravelversions.com/en
- Transformers are used to format, transform, or modify the data before it is sent to the frontend. Transformers allow you to customize how the data is presented in the DataTable, making it more user-friendly or specific to the needs of your application.
- Mappers refer to functions or methods that map data from your model or database to the format or structure required by your DataTable
- Controlled Transitions: A state machine ensures that an entity can only move from one state to another in a predefined way, preventing invalid state changes.
- Business Logic Enforcement: It helps enforce business rules by allowing transitions only when certain conditions are met.
- Simplified Management: It simplifies the management of complex workflows, where an entity might need to go through multiple states in a sequence.
Let's say you have an e-commerce platform, and you need to manage the different states of an order:
-
States:
pending
processing
shipped
delivered
canceled
-
Allowed Transitions:
pending
→processing
processing
→shipped
shipped
→delivered
- Any state →
canceled
(exceptdelivered
)
@todo: https://laravel-news.com/php-codesniffer-with-laravel
https://laravel-news.com/spatie-image-v3
https://dev.to/etienneleba/test-all-your-business-logic-in-less-than-1-second-2n84
https://dev.to/adnanbabakan/implement-uuid-primary-key-in-laravel-and-its-benefits-55o3 \