laravelsnip

كتابات: 
IDE helper: https://github.com/barryvdh/laravel-ide-helper
// Laravel create new project
lando composer create-project laravel/laravel project
// Laravel installation
composer install -n
mkdir -p storage/framework/{sessions,views,cache}
chmod -R 0777 storage/framework
php artisan key:generate
php artisan migrate:refresh --seed
// deploy
cd /var/www/html/$1
git pull
#composer install --no-interaction --no-dev
#composer update -n
composer install --no-interaction
chown www-data:www-data -R /var/www/html/$1
php artisan migrate --force
php artisan optimize:clear
php artisan cache:clear
#php artisan config:clear
#php artisan config:cache
// Useful Laravel commands
php artisan route:list // to list all defined routes
php artisan migrate:fresh --seed // To run the database seeders
* * * * * cd /var/www/html && php artisan schedule:run >> /dev/null 2>&1
// When you want to loop all db table records, use ::cursor()
SOURCE: https://webomnizz.com/working-with-lazy-collection-in-laravel-6/
// https://www.amitmerchant.com/using-lazy-collections-on-memory-hungry-operations-in-laravel6/
// Deploy commands
git pull
composer install --no-interaction --no-dev
php artisan migrate --force
php artisan optimize:clear
php artisan cache:clear
// 20190225
php artisan make:migration create_replies_table
php artisan migrate
// re migrate a specific migration file
php artisan migrate:refresh --path=./database/migrations/FILE_NAME.php
// filament
php artisan make:filament-resource MODEL_NAME_HERE

// Create user
php artisan tinker
DB::table('users')->insert(['name'=>'admin','email'=>'[email protected]','password'=>Hash::make('admin')])

php artisan tinker --execute='User::create(["name"=>"admin", "email"=>"[email protected]", "email_verified_at"=> now(), "password"=> bcrypt("admin")]);'
// Steps to create a new DB table.
1. Create the migrate `php artisan make:model MODE_NAME_HERE -m ` (the -m is to create a migration file for this model)
1. Create a resource with controller. `php artisan make:controller CONTROLLER_NAME_HERE --resource`
1. Add the route to this controller. `Route:resource('posts', 'PostsController');`
php artisan make:command CommandNameHereCommand
// Command signature naming: model:action:column
// https://www.youtube.com/watch?v=o1NVVntEvd0
// Override Filament views templates files .. thanks Rakan
php artisan vendor:publish --tag=filament-views
// Add config variable
1. Go to config/app.php
1. Add your config variable name at the end of this config file. `'your_variable_name' => env('YOUR_VARIABLE_NAME', NULL),`
1. Add the `YOUR_VARIABLE_NAME=hello` into your .env file.
1. You can now get the value by `config('app.your_variable_name')`
// SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique `users_mobile_unique`(`mobile`))
nano app/Providers/AppServiceProvider.php
// use this class
use Illuminate\Support\Facades\Schema;
// in boot()
Schema::defaultStringLength(191);
// then drop the DB
artisan migrate:fresh
// Filament login 403 error
You need to change the `.env` file value of 
APP_ENV=local

Please refer to https://filamentphp.com/docs/2.x/admin/users#authorizing-access-to-the-admin-panel
To allow admin access on non-local environments/
// Ignore SSL certificate for self-signed certificates.
$response = Http::withoutVerifying()
        ->withHeaders(['Authorization' => 'Bearer HERE', 'Cache-Control' => 'no-cache'])
        ->withOptions(["verify"=>false])
        ->post($url,$fields);
// Cronjob command for Laravel cron job
* * * * * /usr/bin/php /var/www/html/artisan queue:work --timeout=30 --tries=1 --stop-when-empty
# Lando file
name: iot
recipe: laravel
config:
  webroot: project/public
  php: 8.1
tooling:
  automatus:
    service: appserver
    description: Install the application at first time.
    cmd:
      #      - cp .env.example .env
      - mkdir -p /app/project/bootstrap/cache
      - mkdir -p /app/project/storage/framework/sessions
      - mkdir -p /app/project/storage/framework/testing
      - mkdir -p /app/project/storage/framework/views
      - mkdir -p /app/project/storage/framework/cache/data
      - mkdir -p /app/project/storage/logs
      - mkdir -p /app/project/storage/app/public/pdf
      # - cp /app/project/.env.example /app/project/.env
      - cd /app/project && composer install
      - php /app/project/artisan key:generate
      #- php /app/project/artisan vendor:publish --all
      # - php /app/project/artisan storage:link --relative
      - php /app/project/artisan storage:link
      - php /app/project/artisan migrate:refresh --seed
      # - php /app/project/artisan tinker --execute='User::create(["name"=>"admin", "email"=>"[email protected]", "email_verified_at"=> now(), "password"=> bcrypt("admin")]);'
  dejavu:
    service: appserver
    description: Install and apply new changes.
    cmd:
      - cd /app/project && composer install --no-interaction
      - php /app/project/artisan migrate --force
      - php /app/project/artisan optimize:clear
      - php /app/project/artisan cache:clear
# my Laravel ignore list
.idea
project/bootstrap/cache
project/storage
project/cache
project/config/ignition.php
project/config/flare.php
project/config/tinker.php

فضلاً إذا أعجبتك هذه الصفحة لاتنسى أن تقوم بمشاركتها