Skip to content

Instantly share code, notes, and snippets.

@TimTruston
Created January 13, 2016 16:34
Show Gist options
  • Save TimTruston/b6aa67d4e6d2a6f5adfb to your computer and use it in GitHub Desktop.
Save TimTruston/b6aa67d4e6d2a6f5adfb to your computer and use it in GitHub Desktop.

Revisions

  1. TimTruston created this gist Jan 13, 2016.
    73 changes: 73 additions & 0 deletions AppURL.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,73 @@
    <?php

    use Illuminate\Console\Command;
    use Symfony\Component\Console\Input\InputOption;
    use Symfony\Component\Console\Input\InputArgument;

    class AppURL extends Command {

    /**
    * The console command name.
    *
    * @var string
    */
    protected $name = 'app:url {url}';

    protected function getArguments()
    {
    return [
    ['url', InputArgument::OPTIONAL, 'required argument url']
    ];
    }
    /**
    * The console command description.
    *
    * @var string
    */
    protected $description = 'Update the expected app url';


    /**
    * Create a new command instance.
    *
    * @return void
    */
    public function __construct()
    {
    parent::__construct();
    }

    /**
    * Execute the console command.
    *
    * @return void
    */
    public function fire()
    {
    $this->comment('');
    $this->comment('=====================================');
    $this->comment('');

    if(!$this->argument('url')){
    $this->info('url: '.Config::get('app.url'));
    }
    else{
    try
    {
    $path = app_path('config/'.App::environment().'/app.php');
    $contents = File::get($path);
    $contents = preg_replace("/'url' => '(.*?)'/", "'url' => '".$this->argument('url')."'", $contents);
    File::put($path, $contents);

    $this->info('Sucessfully updated the url!');
    }
    catch(Exception $e){
    $this->info('There was a problem updating the url!');
    $this->info(json_encode($e->getMessage()));
    die;
    }
    }
    }


    }