Laravel: полезные команды

24/01/2023

Сниппеты команд для работы с Laravel

art migrate --seed --env=testing
art migrate:fresh
art db:seed
art db:wipe
art db:seed --class=UsersSeeder

art make:model 
art make:migration AddSoftDeletesToPostsTable 
art make:factory Post
php artisan make:model PostTag
php artisan make:model PostTag --pivot
art make:controller -r --force -m Post PostController
art make:controller -i PostShow

art route:list
art route:cache
art route:clear

art make:request Post/PostStoreRequest
art make:request Post/PostUpdateRequest

art make:provider NotificationServiceProvider

art make:migration CreateUserRolesTable 

art make:policy PostPolicy --model=Post
art make:policy TagPolicy --model=Tag

art make:test -u CalcServiceTest
art make:middleware CheckAge
art make:middleware CheckCountry


art make:test AdminPostControllerTest

composer dump-autoload


composer req arcanedev/log-viewer

php artisan log-viewer:publish
php artisan log-viewer:check

php artisan storage:link

art tinker

art vendor:publish
art make:command ChangePostStatus
art make:command ChangeUserPassword

art make:command ChangeUserPassword
art make:job HanlePostCreated
art make:job CalcTransactions

art queue:work
art queue:listen 
art queue:failed-table 

art make:event TransactionCalcFinished
art make:listener LogTransactionsCount --event=TransactionCalcFinished

php artisan make:provider ComposerServiceProvider

composer require watson/rememberable 



composer global require "laravel/envoy=~1.0"
php vendor/bin/envoy run deploy --branch=master

art make:controller -m Post --api Api/PostController
art make:resource PostResource
art make:resource PostV2Resource

art make:resource -c PostsResource
art make:controller -i ShowPostApiV2Controller
art make:controller -i ShowPostApiV2Controller

composer req php-open-source-saver/jwt-auth
PHPOpenSourceSaver\JWTAuth\Providers\LaravelServiceProvider::class,

php artisan vendor:publish --provider="PHPOpenSourceSaver\JWTAuth\Providers\LaravelServiceProvider"
php artisan jwt:secret
art make:controller -i Api/LoginController

vendor/bin/phpunit  -c local/tests/phpunit.xml.dist 
vendor/bin/phpunit --coverage-html cove 
./vendor/bin/phpunit --testdox tests

service php8.1-fpm status

composer req illuminate/support ^9.19
composer req illuminate/routing ^9.19
composer req illuminate/http ^9.19

Clear cache before you deploy the application
php artisan cache:clear
Clear cache manually
rm -rf bootstrap/cache/*.php



Работа с Redis

composer require predis/predis

http://localhost:9987/?view&s=0&d=0&key=as1
secret_redis

127.0.0.1:6379> flushall

127.0.0.1:6379> keys *

127.0.0.1:6379> get key


select 15

type megablog_database_queues:default

127.0.0.1:6379> LRANGE megablog_database_queues:default 0 -1

Проверка Memcached


php -r '$c = new Memcached(); $c->addServer("localhost", 11211); var_dump( $c->getAllKeys() );'

Хоткеи в PhpStorm


ctrl+alt+shift+C
копирует вместе с неймспейсом класс

ctrl+alt+V вынести в переменную
ctrl+alt+M вынести в метод



Проверить, занят ли порт


// Проверяем, занят ли порт 80

sudo lsof -i :80
Метод второй:

netstat -anp tcp | grep 80
Следующая команда может напрямую завершить все процессы, занимающие порт:

lsof -P | grep ':80' | awk '{print $2}' | xargs kill -9



Теги - Laravel , Php