I got this DatabaseSeeder.php in laravel where I create a Directory:
public function run()
{
Storage::deleteDirectory('posts');
Storage::makeDirectory('posts');
// Etcetera ...
}
And then I run
$ php artisan migrate:fresh --seed
This works flawlessly in my development environment (Laravel Homestead).
However, if I run that same command inside a Docker container using Laradock, I get the following error:
Seeding: Database\Seeders\PostsSeeder
InvalidArgumentException
Cannot write to directory "public/storage/posts"
at vendor/fakerphp/faker/src/Faker/Provider/Image.php:90
86▕ ) {
87▕ $dir = is_null($dir) ? sys_get_temp_dir() : $dir; // GNU/Linux / OS X / Windows compatible
88▕ // Validate directory path
89▕ if (!is_dir($dir) || !is_writable($dir)) { ➜ 90▕ throw new \InvalidArgumentException(sprintf('Cannot write to directory
"%s"', $dir));
91▕ }
92▕
93▕ // Generate a random filename. Use the server address so that a file
94▕ // generated at the same time on a different server won't have a collision.
+3 vendor frames
database/factories/ImageFactory.php:25
Faker\Generator::__call()
Why is this happening?
How do I fix it?
Workaround
To easily solve it simply create those directories:
$ ls -lah public/
$ cd public/ && mkdir storage && cd storage && mkdir posts && cd ../..
Try again
$ artisan migrate:refresh --seed
This error is because one of your "Factory" files, in the "faker" method in this case, the "posts" folder does not exist.
Faker does not have the ability to create a new folder and since the folder does not exist, I get that error.
So in this case you have to create the posts folder first. To do this, inside your "DatabaseSeeder.php" file, place the following line of code inside the run () method at the beginning:
use Illuminate\Support\Facades\Storage;
public function run()
{
Storage::deleteDirectory('public/posts');
Storage::makeDirectory('public/posts');
...
}
I had the same problem, I create the folder using the workaround, and it works, but running artisan migrate: refresh --seed doesn't remove the directories but creates more.
public function run()
{
Storage::deleteDirectory('posts');
Storage::makeDirectory('posts');
// Etcetera ...
}
Related
I'm trying to build the hasura cli: https://github.com/hasura/graphql-engine/tree/master/cli with the following code (deps derived from dep2nix):
{ buildGoPackage, fetchFromGitHub }:
buildGoPackage rec {
version = "1.0.0-beta.2";
name = "hasura-${version}";
goPackagePath = "github.com/hasura/graphql-engine";
subPackages = [ "cli" ];
src = fetchFromGitHub {
owner = "hasura";
repo = "graphql-engine";
rev = "v${version}";
sha256 = "1b40s41idkp1nyb9ygxgsvrwv8rsll6dnwrifpn25bvnfk8idafr";
};
goDeps = ./deps.nix;
}
but I get the following errors after the post-installation fixup step:
find: '/nix/store/gkck68cm2z9k1qxgmh350pq3kwsbyn8q-hasura-cli-1.0.0-beta.2': No such file or directory.
What am I doing wrong here? For reference, I'm on macOS and using home-manager.
For anyone still wondering:
There are a couple of things to consider:
dep has been deprecated in favor of go modules
This is also reflected in Nix, as buildGoPackage is now legacy and moved to buildGoModule
There is already a hasura-cli package in nixpkgs. You can just use it with nix-shell -p hasura-cli
I was curious about setting up an API in Laravel using Passport so I followed their documentation here:
https://laravel.com/docs/5.6/passport
Once I run
php artisan passport:install
It gives me this error:
ErrorException : openssl_pkey_new(): private key length is too short; it needs to be at least 384 bits, not 0
at /Users/fantastisk/web/blog-laravel/vendor/phpseclib/phpseclib/phpseclib/Crypt/RSA.php:560
556| $config = array();
557| if (isset($this->configFile)) {
558| $config['config'] = $this->configFile;
559| }
> 560| $rsa = openssl_pkey_new(array('private_key_bits' => $bits) + $config);
561| openssl_pkey_export($rsa, $privatekey, null, $config);
562| $publickey = openssl_pkey_get_details($rsa);
563| $publickey = $publickey['key'];
564|
Exception trace:
1 openssl_pkey_new(["4096", "/Users/fantastisk/web/blog-laravel/vendor/phpseclib/phpseclib/phpseclib/Crypt/../openssl.cnf"])
/Users/fantastisk/web/blog-laravel/vendor/phpseclib/phpseclib/phpseclib/Crypt/RSA.php:560
2 phpseclib\Crypt\RSA::createKey("4096")
/Users/fantastisk/web/blog-laravel/vendor/laravel/passport/src/Console/KeysCommand.php:35
This is what i have in the openssl.cnf file
# minimalist openssl.cnf file for use with phpseclib
HOME = .
RANDFILE = $ENV::HOME/.rnd
distinguished_name = req_distinguished_name
[ v3_ca ]
I'm running on a mac with php 7.1 (i tried building it from source with openssl too), SSL Version => LibreSSL/2.0.20.
I tried following the documentation using homestead too, which gives me the exact same error.
To me it seems like there's a problem with the phpseclib library, but I haven't been able to find anything on google regarding this error.
As a final note, I tried running this command to check if openssl_pkey_new works:
openssl_pkey_new(array("digest_alg" => "sha512","private_key_bits" => 4096,"private_key_type" => OPENSSL_KEYTYPE_RSA,));
That worked with no error.
Any help or point in the right direction will be very much appreciated.
Try passing the length option as you run the install command:
php artisan passport:install --length=256
If that doesn't work then try forcing the key generation:
php artisan passport:key --force
You may need to run composer update prior.
Hi got a LEMP stack un Ubuntu 18.04 with php 7.2.5
server info says
Shell Exec Is Supported
Shell Exec Zip Not Supported
therefore some of my plugins says
This server is not configured for the Shell Zip engine - please use a different engine mode. To make 'Shell Zip' available, ask your host to:
1. Install the zip executable and make it accessible to PHP.
I have tries this code
PHP - How to know if server allows shell_exec
if(function_exists('shell_exec')) {
echo "exec is enabled";
}
and the function is enabled
however when i test if it is executable with the code below nothing happens.
As DanFromGermany pointed out, you probably check then if it is
executable. Something like this would do it
if(shell_exec('echo foobar') == 'foobar'){
echo 'shell_exec works';
}
or tried this, returns nothing as well just white page
// Exec function exists.
// Exec is not disabled.
// Safe Mode is not on.
$exec_enabled =
function_exists('exec') &&
!in_array('exec', array_map('trim', explode(', ', ini_get('disable_functions')))) &&
strtolower(ini_get('safe_mode')) != 1
;
if($exec_enabled) { exec('blah'); }
I have also checked with the code below from https://wpguru.co.uk/2014/01/how-to-test-if-a-shell-command-will-work-in-php/ and it does work
// helper function
function checkShellCommand($command) {
$returnValue = shell_exec("$command");
if(empty($returnValue)) {
return false;
} else {
return true;
}
}
// test the shell command you'd like to use
if (!checkShellCommand('uname -a')) {
print 'This command cannot be executed.';
} else {
echo shell_exec('uname -a');
}
So, could anyone tell me how can I make it accessible to PHP
Many thanks
this was solved by
apt-get install zip unzip
Is there any recipe for adding a new, empty directory to the rootfs? I tried adding this into one of my bbappend file:
do_install() {
install -d ${D}/tmp/myNewDir
}
FILES_${PN} += "/tmp/myNewDir"
but I am getting a non descriptive error, Function failed: do_install
There are several ways. The image command way is already described by StackedUser.
You can also try to extend some of your recipes (as you are doing in your question). I guess that you are seeing the error because you are overwriting the do_install task. You are probably wanting to extend it, so you should add _append to the task name, i.e.:
do_install_append () {
install -d ${D}/tmp/myNewDir
}
BTW, the error "Function failed: do_install" you are hitting usually show an error code or a problematic command. Maybe there is something.
Another way is to create a simple recipe and add it to the image, here is a stub:
SUMMARY = "XXX project directory structure"
# FIXME - add proper license below
LICENSE = "CLOSED"
PV = "1.0"
S = "${WORKDIR}"
inherit allarch
do_install () {
install -d ${D}/foo/bar
}
FILES_${PN} = "/foo/bar"
In our image recipe we have something like this to create a new directory:
create_data_dir() {
mkdir -p ${IMAGE_ROOTFS}/data
}
IMAGE_PREPROCESS_COMMAND += "create_data_dir;"
I'm using laravel 4 and I need to change an uploaded image, I have it in:
Public
--uploads
---news
----id_news.jpg
When editing the new's I want to make a change image form, but how could I delete and upload another file. I am using:
Input::file('img')->move('uploads/news', $id.'_news.jpg');
The problem it's that it doesn't work, it's not replacing the file, so how could I delete The image so I could upload again.
In laravel 3 I only used:
File::delete('path/to/file');
But I don't see anything about removing files in laravel docs.
I think you should append public_path() to file names , to get real file path, like this
File::delete(public_path().$id.'_news.jpg');
There is still the delete method in Laravel 4:
src/Illuminate/Filesystem/Filesystem.php
otherwise just use good old unlink()!?
You can easily do something like:
$filename = public_path().'/uploads/foo.bar';
if (File::exists($filename)) {
File::delete($filename);
}
Reference: Laravel-recipes Delete a File
Other delete usage:
// Delete a single file
File::delete($filename);
// Delete multiple files
File::delete($file1, $file2, $file3);
// Delete an array of files
$files = array($file1, $file2);
File::delete($files);
Source: http://laravel-recipes.com/recipes/133/deleting-a-file
$destinationPath = 'uploads/my-image.jpeg'; // from public/
if ( File::exists($destinationPath) ) {
File::delete($destinationPath);
}
This works on laravel 4.2.
File::delete(storage_path()."/ProductSalesReport-20150316.csv");
// Here are some other paths to directories laravel offers, Hope this
helps
/* Path to the 'app' folder */
echo app_path();
/* Path to the project's root folder */
echo base_path();
/* Path to the 'public' folder */
echo public_path();
/* Path to the 'app/storage' folder */
echo storage_path();