Lumen 5.4 with Laravel Mailable - laravel

Naive question: is there a way to use Artisan to create a Mailable class within Lumen framework like this: php artisan make:mail OrderShipped (example taken from the docs).
Here is the composer.json
{
"name": "laravel/lumen",
"description": "The Laravel Lumen Framework.",
"keywords": ["framework", "laravel", "lumen"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"laravel/lumen-framework": "5.4.*",
"vlucas/phpdotenv": "~2.2",
"firebase/php-jwt": "^4.0",
"guzzlehttp/guzzle": "^6.3",
"illuminate/mail": "5.4",
"phanan/cascading-config": "~2.0"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"phpunit/phpunit": "~5.0",
"mockery/mockery": "~0.9"
},
"autoload": {
"psr-4": {
"App\\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/",
"database/"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"copy('.env.example', '.env');\""
]
},
"minimum-stability": "dev",
"prefer-stable": true
}
This is how bootstrap/app.php has been modified (added all of these):
$app->withFacades( true, [
'Illuminate\Support\Facades\Mail' => 'Mail',
]);
$app->register(\Illuminate\Mail\MailServiceProvider::class);
$app->configure('mail');
$app->alias('mailer','Illuminate\Mail\Mailer');
config('mail');
And this is what php artisan gives me:
Laravel Framework Lumen (5.4.7) (Laravel Components 5.4.*)
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--env[=ENV] The environment the command should run under
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
help Displays help for a command
list Lists commands
migrate Run the database migrations
auth
auth:clear-resets Flush expired password reset tokens
cache
cache:clear Flush the application cache
cache:forget Remove an item from the cache
cache:table Create a migration for the cache database table
db
db:seed Seed the database with records
make
make:migration Create a new migration file
make:seeder Create a new seeder class
migrate
migrate:install Create the migration repository
migrate:refresh Reset and re-run all migrations
migrate:reset Rollback all database migrations
migrate:rollback Rollback the last database migration
migrate:status Show the status of each migration
queue
queue:failed List all of the failed queue jobs
queue:failed-table Create a migration for the failed queue jobs database table
queue:flush Flush all of the failed queue jobs
queue:forget Delete a failed queue job
queue:listen Listen to a given queue
queue:restart Restart queue worker daemons after their current job
queue:retry Retry a failed queue job
queue:table Create a migration for the queue jobs database table
queue:work Start processing jobs on the queue as a daemon
schedule
schedule:run Run the scheduled commands
I am on OS X El Capitan, Apache2, PHP 5.6.31
So again, how (if at all) can I use artisan to make:mail? If this is not achievable without full-blown Laravel, is there a template to create Mailable classes? Will they be usable?
Refs:
https://laravel.com/docs/5.4/mail#generating-mailables
https://scotch.io/tutorials/easy-and-fast-emails-with-laravel-5-3-mailables
Lumen 5.3 send email (no make:mail?)

Yes, there are some packages that allow that exactly. For example:
https://github.com/flipboxstudio/lumen-generator
As stated on their readme, to install the Composer package:
composer require flipbox/lumen-generator
And then add on bootstrap/app.php file:
$app->register(Flipbox\LumenGenerator\LumenGeneratorServiceProvider::class);
If you then run php artisan on command line, you get new commands:
Available commands:
clear-compiled Remove the compiled class file
help Displays help for a command
list Lists commands
migrate Run the database migrations
optimize Optimize the framework for better performance
serve Serve the application on the PHP development server
tinker Interact with your application
key
key:generate Set the application key
make
make:command Create a new Artisan command
make:controller Create a new controller class
make:event Create a new event class
make:job Create a new job class
make:listener Create a new event listener class
make:mail Create a new email class
make:middleware Create a new middleware class
make:migration Create a new migration file
make:model Create a new Eloquent model class
make:policy Create a new policy class
make:provider Create a new service provider class
make:seeder Create a new seeder class
make:test Create a new test class

Related

Laravel 8 on App Engine: "Please provide a valid cache path"

I upgraded a Laravel project from version 7 to 8. When I attempt to deploy it on App Engine, it fails saying "Please provide a valid cache path":
Updating service [***]...failed.
ERROR: (gcloud.app.deploy) Error Response: [9] Cloud build [***] status: FAILURE
Error type: UNKNOWN
[...]
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> #php artisan package:discover --ansi
In Compiler.php line 36:
Please provide a valid cache path.
Part of my composer.json:
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"#php artisan package:discover --ansi",
"#php artisan vendor:publish --force --tag=livewire:assets --ansi"
],
"post-create-project-cmd": [
"#php artisan key:generate --ansi"
],
"post-update-cmd": [
"Illuminate\\Foundation\\ComposerScripts::postUpdate",
"#php artisan ide-helper:generate",
"#php artisan ide-helper:meta"
],
"post-install-cmd": [
"composer dump-autoload",
"php artisan config:clear",
"php artisan cache:clear",
"php artisan view:clear",
"php artisan cache:clear",
"php artisan optimize:clear"
]
A snippet from app.yaml:
env_variables:
APP_STORAGE: /tmp
VIEW_COMPILED_PATH: /tmp
APP_SERVICES_CACHE: /tmp/services.php
APP_PACKAGES_CACHE: /tmp/packages.php
APP_CONFIG_CACHE: /tmp/config.php
APP_ROUTES_CACHE: /tmp/routes.php
CACHE_DRIVER: database
SESSION_DRIVER: database
I do have /storage/framework/views folder along with the other standard folders under /storage as well as bootstrap/cache.
If I remove this line from composer.json (under "post-autoload-dump"):
"#php artisan vendor:publish --force --tag=livewire:assets --ansi"
I am able to deploy the app but it fails on pages that use Livewire components with the following error:
The /workspace/bootstrap/cache directory must be present and writable. (View: /workspace/resources/views/users/edit.blade.php)
ErrorException
in /workspace/vendor/livewire/livewire/src/LivewireComponentsFinder.php (line 58)
in /workspace/vendor/livewire/livewire/src/CompilerEngine.php -> handleViewException (line 41)
in /workspace/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php -> handleViewException (line 60)
in /workspace/vendor/livewire/livewire/src/LivewireViewCompilerEngine.php -> evaluatePath (line 36)
in /workspace/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php -> evaluatePath (line 61)
in /workspace/vendor/laravel/framework/src/Illuminate/View/View.php -> get (line 139)
This happens even though I added the following line to bootstrap/app.php:
$app->useStoragePath(env('APP_STORAGE', base_path() . '/storage'));
following the guide.
Prior to upgrading Laravel, I had no problems deploying the app on App Engine.
This is a really annoying error. It happened every now and then and I still haven't found a fix. I'm sure that there is something weird happening in Cloud Build, I just don't know what. Anyone have any ideas other that the mentioned above please share.
Edit
I believe the issue lies complied views path as explained here
Now, setting VIEW_COMPILED_PATH to /tmp is necessary for the app to run BUT, the error occurs during build. During build, the compiled views cache path is read not from app.yaml but from the config/view.php or maybe .env where the value usually is realpath(storage_path('framework/views')). Now, that is absolutely fine under normal circumstances. The last piece of the puzzle is gcloud app deploy which will for some reason neglect to deploy empty directories or directories with only .gitignore in them, hence, storage/framework/views will not be deployed and during build the error will occur.
Possible fixes:
Add some random file (other than .gitignore) in 'storage/framework/views' before deploying to make sure the directory is available during build.
Change the default value in config/views to a directory that is present during build.
Any other way to ensure that storage/framework/views is not ignored (present during build) should do.
My working solution was to edit config/view.php:
'compiled' => env(
'VIEW_COMPILED_PATH',
isset($_SERVER['GAE_SERVICE']) ?
'/tmp'
: realpath(storage_path('framework/views'))
),
This will make sure that the default location for compiled views when the app is running on GAE machine is located to /tmp directory instead of storage/framework/views.
The solution was to update the Livewire dependency.
Before:
"livewire/livewire": "^1.1",
After:
"livewire/livewire": "^2.1",
Any version beginning with 2.0 seems to work.

Laravel ide-helper installed fine but doesn't generate

BarryVdh's ide-helper has been sucessfully installed to my Laravel project as the composer.json desribes:
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
...
},
"require-dev": {
...
"barryvdh/laravel-ide-helper": "^2.1",
"doctrine/dbal": "^2.9"
},
Added to providers in app/config as:
'providers' => [
...
Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class,
],
I assume it partially works as the command php artisan ide-helper:meta generates .phpstorm.meta.php in the root folder, but the php artisan ide-helper:generate command fails with the following simple error:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Parse error: syntax error, unexpected end of file
If I try to generate model info with the command php artisan ide-helper:models, asks for overwrite models or to write to _ide_helper_models.php instead, 'no' chosen, it fails and throws the same error above. However, if I add a model to the command (eg. php artisan ide-helper:models Order ), after choosing 'no' for overwrite the ide-helper generates the _ide_helper_models.php file without any relevant content, just the default comment block.
What to check in this case?
(phpStorm IDE, win10, Laravel 5.1, Xampp, PHP7)

Nova Tool not updating

I'm making a Laravel Nova app. I'm trying to create a Nova Tool to import users.
The tool creates just fine, however when i update the code it does not show.
I've digged a bit into this, and the problem seems to be that the tool in the Vendor folder does not get updated.
When i do npm run dev or npm run prod, the tool files get updated inside the /nova-components/{componentname} folder, and not in the vendor folder, which is getting loaded by Nova.
I'm using Xampp on windows.
Inside my nova service provider:
/**
* Get the tools that should be listed in the Nova sidebar.
*
* #return array
*/
public function tools()
{
return [
new UserImport()
];
}
My composer file:
"require": {
"Vrumona/UserImport": "*"
},
"repositories": [
{
"type": "path",
"url": "./nova"
},
{
"type": "path",
"url": "./nova-components/UserImport"
}
],
How do make sure the Tool gets updated in the composer vendor folder?
I can delete the vendor folder and run composer install, but this is a bit tedious while developping.
Thanks!
It is likely that composer is not symlinking the package but rather mirroring. You can confirm by seeing what the output is when you run composer update -- if you see Mirrored from ... then symlinks are unavailable which will cause the issue that you're seeing.
As you noticed, you can force symlinks in the composer file using:
"options": {
"symlink": true // Will force symlinks
}
And the relevant documentation if needed: https://getcomposer.org/doc/05-repositories.md#path
php artisan cache:clear
php artisan route:clear
php artisan config:clear
php artisan view:clear

Publishing custom package files using Laravel with composer

I have created new package and i want to avoid publish command separately and i need to include publish command inside package composer.json file. So when package is install it should move the files according to service provider path.
I tried below method but assets/files are not published.
"scripts": {
"post-install-cmd": [
"php artisan vendor:publish --provider=\"<vendorname>\\<packagename>\\<Serviceprovider>\" --tag=public --force",
"php artisan migrate"
],
"post-update-cmd": [
"php artisan vendor:publish --provider=\"<vendorname>\\<packagename>\\<Serviceprovider>\" --tag=public --force",
"php artisan migrate"
]
}
But it works fine when directly run the command like below
php artisan vendor:publish --provider="<vendorname>\<packagename>\<Serviceprovider>"
Please provide solution for it.
Did you try with below code manually. If it returns the thing you need, then you are on the right track. Else some typo is on command of script.
composer run-script post-install-cmd
Composer does not support automatically running scripts other than those at root level. This is somewhat contested, but doesn't look like it's going to change any time soon.
Your best bet is probably to manually run the command / instruct users to manually run the command in your readme: composer run-script post-install-cmd -d ./vendor/[name]/[package]
Maybe you should try to use # before command, and also I suggesting to you to try write command in "post-autoload-dump" section. It is work for me.
"scripts": {
"post-autoload-dump": [
"#php artisan vendor:publish --provider='<vendorname>\\<packagename>\\<Serviceprovider>' --tag=public --force",
"#php artisan migrate"
]
}

Laravel run package migration by composer update automatic

I have a package and my ServiceProvider copies the migrations. This works fine after php artisan migrate. But now i want to execute the package migration when i do composer update name/name-package.
So, php artisan update name/packagename and directly automaticly migrate.
How can i achieve that?
$this->publishes([
__DIR__ . '/database/migrations' => $this->app->databasePath() . '/migrations'
], 'migrations');
in application (not package) composer.json
"scripts": {
"post-update-cmd": [
"php artisan optimize",
"php artisan migrate"
]
}
the order of commands is up to you. Also, you may create a command or use php artisan vendor:publish --provider=... to move the migrations

Resources