

Automate App Setup with Laravel Initializer
source link: https://laravel-news.com/automate-app-setup-with-laravel-initializer
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Have you ever found yourself writing multiple manual steps to set up a Laravel application in a new environment? Laravel Initializer is a convenient way to automate installing and updating a Laravel application:
Laravel Initializer gives you the ability to declare multiple processes and run them with app:install and app:update artisan commands, which run predefined actions chain depending on the current environment.
The app:install
and app:update
commands use two distinct classes that run commands based on a given environment. First, the install
command uses the App\Install
class:
namespace App; use MadWeb\Initializer\Contracts\Runner; class Install { public function production(Runner $run) { return $run ->external('composer', 'install', '--no-dev', '--prefer-dist', '--optimize-autoloader') ->artisan('key:generate') ->artisan('migrate', ['--force' => true]) ->artisan('storage:link') ->external('npm', 'install', '--production') ->external('npm', 'run', 'production') ->artisan('route:cache') ->artisan('config:cache') ->artisan('event:cache'); } public function local(Runner $run) { return $run ->external('composer', 'install') ->artisan('key:generate') ->artisan('migrate') ->artisan('storage:link') ->external('npm', 'install') ->external('npm', 'run', 'development'); } }
The app:update
command looks similar, using an App\Update
class:
namespace App; use MadWeb\Initializer\Contracts\Runner; class Update { public function production(Runner $run) { return $run ->external('composer', 'install', '--no-dev', '--prefer-dist', '--optimize-autoloader') ->external('npm', 'install', '--production') ->external('npm', 'run', 'production') ->artisan('route:cache') ->artisan('config:cache') ->artisan('event:cache') ->artisan('migrate', ['--force' => true]) ->artisan('cache:clear') ->artisan('queue:restart'); ->artisan('horizon:terminate'); } public function local(Runner $run) { return $run ->external('composer', 'install') ->external('npm', 'install') ->external('npm', 'run', 'development') ->artisan('migrate') ->artisan('cache:clear'); } }
You can also inject dependencies from the service container if you need to access services while running commands.
This package contains a variety of runner actions you should check out in the readme. I found the MakeCronTask
dispatch interesting:
$run->dispatch(new \MadWeb\Initializer\Jobs\MakeCronTask)
MakeCronTask adds the following to the server’s crontab list:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
You can do other things like creating a supervisord config for a typical queue worker or horizon.
You can learn more about this package, get full installation instructions, and view the source code on GitHub at mad-web/laravel-initializer .
Recommend
-
81
-
43
Instructor: 00:00 Let's look at several ways. We could use npm to create applications. First, let's take a look at building a React app three different ways using create-react-app. If you have npm version 5.1...
-
55
In this post, we are going to look at how we can use APP_INITIALIZER in Angular. So, what exactly does APP_INITIALIZER do? The best way to answer that is by looking at my previouspost, which can be foundhere. It was abou...
-
25
Pop quiz: what does the following C++ program do? #include <memory> #include <string> #include <vector> using namespace std; int main() { vector<unique_ptr<string>> vec{...
-
75
PHP RFC: Object Initializer Version: 1.0 Date:...
-
19
Objects can be initialized using new Object(),
-
10
Intro to creating UI in code (programmatically) part 1 / 2 - Create UI using initializer by Axel Kee 23 Sep 2018 swift,
-
8
Tweet / TwitterDon’t miss what’s happeningPeople on Twitter are the first to know.
-
17
从理论到实践: ORB-SLAM3 Initializer完全解读 ...
-
14
ORB-SLAM3 Initializer.cpp函数解读 Original...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK