Set User Permissions | Artisan Command Will Not Run in Code But Works Fine on Command Line

Set user permissions | Artisan command will not run in code but works fine on command line

You can either set permissions to the folder by

chmod 777 -R /path/to/folder

what you absolutely shouldn't do, as everybody can write and execute everything in this directory afterwards

or, what I would prefer, you create a new group, let's call it usergroup:

sudo groupadd usergroup

Now that the group exists, add the two users to it:

sudo usermod -a -G usergroup <your username>
sudo usermod -a -G usergroup www-data

Now all that's left is to set the permissions on the directory:

sudo chgrp -R usergroup /path/to/the/directory
sudo chmod -R 770 /path/to/the/directory // <<<<<< change this to 775

Now only members of the usergroup group can read, write, or execute files and folders within the directory. Note the -R argument to the chmod and chgrp commands: this tells them to recurse into every sub directory of the target directory and modify every file and directory available.

You may also want to change 770 to something like 774 if you want others to be able to read the files, 775 if you want others to read and execute the files, etc. Group assignment changes won't take effect until the users log out and back in.

In your case, you should definately change it to 775 afterwards...

Why command php artisan serve not working

try

php -S localhost:8000 -t public/

source : http://allbitsnbytes.com/posts/php-artisan-serve-not-working/

How to ignore Console Command while running a pre defined artisan command

Please check your commands and see if those are jobs are being performed from the constructor.
if its loading from the constructor then it will be running when any command is being executed. because it builds every command when we run any command from cli. so just move it to the handle() instead of __construct()

Create Artisan command with option that must specify a value

Poking around the Laravel code, I confirmed that there is no way to have a truly "required" value. Although Symfony does provide for required values, Laravel doesn't use this capability. Instead the options are all created as optional, so I will have to write my own parser...

This was fairly straightforward; I had to write a custom parser class to override the Illuminate\Console\Parser::parseOption() method, and then override Illuminate\Console\Command::configureUsingFluentDefinition() to use that new class.

I elected to create a new option type, rather than change the behaviour of any existing command options. So now I declare my signature like this when I want to force a value:

<?php

namespace App\Console\Commands;

use App\Console\Command;

class MyCommand extends Command
{
/** @var string The double == means a required value */
protected $signature = "mycommand {--t|test==}";

...
}

Attempting to run artisan mycommand -t will now throw a Symfony\Component\Console\Exception\RuntimeException with a message of "The --test option requires a value." This also works for array options (--t==*) and/or options with default values (--t==42 or --t==*42.)

Here's the code for the new parser class:

<?php

namespace App\Console;

use Illuminate\Console\Parser as BaseParser;
use Symfony\Component\Console\Input\InputOption;

class Parser extends BaseParser
{
protected static function parseOption($token): InputOption
{
[$mytoken, $description] = static::extractDescription($token);

$matches = preg_split("/\\s*\\|\\s*/", $mytoken, 2);

if (isset($matches[1])) {
$shortcut = $matches[0];
$mytoken = $matches[1];
} else {
$shortcut = null;
}

switch (true) {
case str_ends_with($mytoken, "=="):
return new InputOption(
trim($mytoken, "="),
$shortcut,
InputOption::VALUE_REQUIRED,
$description
);
case str_ends_with($mytoken, "==*"):
return new InputOption(
trim($mytoken, "=*"),
$shortcut,
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
$description
);
case preg_match("/(.+)==\*(.+)/", $mytoken, $matches):
return new InputOption(
$matches[1],
$shortcut,
InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
$description,
preg_split('/,\s?/', $matches[2])
);
case preg_match("/(.+)==(.+)/", $mytoken, $matches):
return new InputOption(
$matches[1],
$shortcut,
InputOption::VALUE_REQUIRED,
$description,
$matches[2]
);
default:
// no == here, fall back to the standard parser
return parent::parseOption($token);
}
}
}

And the new command class:

<?php

namespace App\Console;

use Illuminate\Console\Command as BaseCommand;

class Command extends BaseCommand
{
/**
* Overriding the Laravel parser so we can have required arguments
*
* @inheritdoc
* @throws ReflectionException
*/
protected function configureUsingFluentDefinition(): void
{
// using our parser here
[$name, $arguments, $options] = Parser::parse($this->signature);

// need to call the great-grandparent constructor here; probably
// could have hard-coded to Symfony, but better safe than sorry
$reflectionMethod = new ReflectionMethod(
get_parent_class(BaseCommand::class),
"__construct"
);
$reflectionMethod->invoke($this, $name);

$this->getDefinition()->addArguments($arguments);
$this->getDefinition()->addOptions($options);
}
}


Related Topics



Leave a reply



Submit