laravel, php, Uncategorized

Custom Facades in Laravel 4.2.X

// file System












Name of Custom Facade "Sky"


1. create a new folder facades inside app folder

2. create a new folder same name as of your custom facade name. [ eg: app/facades/Sky / ]

3 create one more folder inside app / [ your facade folder ] / Facade

4. now create 2 files in the your facade base

              / Helper.php
              / HelperServiceProvider.php

5. a facade class inside a

=============== Contents inside files =================
## app/facades/Sky/Helper.php

namespace Sky;
Class Helper {

	public function fire()
		return 'Fireing ... ';

	public function boom()
		return 'Fireing boom... ';

## app/facades/Sky/HelperServiceProvider.php

namespace Sky;
use Illuminate\Support\ServiceProvider;

class HelperServiceProvider extends ServiceProvider {

    public function register()
        // Registering 'helper class'
        $this->app['helper'] = $this->app->share(function($app)
            return new Sky\Helper;

        // dynamic creating Alias, so that you do not have to add an Alias in app/config/app.php
            $loader = \Illuminate\Foundation\AliasLoader::getInstance();
            $loader->alias('SkyHelper', 'Sky\Facade\Helper');

## app/facades/Sky/Facade/Helper.php

namespace Sky\Facade;

use Illuminate\Support\Facades\Facade;

class Helper extends Facade {

     * Get the registered name of the component.
     * @return string
    protected static function getFacadeAccessor() { return 'Sky\Helper'; }


### this is it all you need for your custom facades ##########

### one more last thing you need to do for autoload the facade classes ####
# GO to composer.json, add new line app/facades for autoloading.

"autoload": {
		"classmap": [

finally RUN " composer dump-autoload "

Cheers enjoy

Removing /public/ folder from Laravel

As inspired by CI ,

1. Create a “system” folder in root.

2. Move all the files to system except the public folder.

3. Move all the files form public to root folder.

It should now looking something like attached screen shot below.

Screen Shot 2014-08-22 at 1.21.11 PM


4. Reconfigure the paths


'app' => __DIR__.'/../app',
'public' => __DIR__.'/../public',

Change these two lines to:

'app' => __DIR__.'/../app',
'public' => __DIR__.'/../../',

Find these lines in index.php

require __DIR__.'/../bootstrap/autoload.php';
$app = require_once __DIR__.'/../bootstrap/start.php';

And change to:

$app= require_once__DIR__.'/system/bootstrap/start.php';


Now time to remove index.php form url 

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]


Cheers enjoy.

laravel, php

changing mac’s default php setting to xamp [ enabling mcrypt in mac lion]

To those that uses XAMPP 1.7.3 and Mac

  1. Go to Terminal
  2. Enter which php
    • If it says /usr/bin/php, then proceed to 3.
  3. Enter sudo nano ~/.bash_profile
  4. then paste this export PATH="/Applications/XAMPP/xamppfiles/bin:$PATH"
  5. ctrl – O then enter to save, then ctrl – X to exit.
  6. restart terminal.
  7. Enter which php
    • If you did it right, it should be the same as the path in #4.

The reason for the mcrypt error is because your mac uses it’s native php, you need to change it to the one xampp has.

Some of useful commands to test php settings in mac lion

>> which PHP  // to see if mac is using default php server or third party php setting [ xamp or mamp ]

>> php –version  // to see the php version

>> php -m  // to see the active modules / extensions



Reference :