PHPackages                             ghunti/laravel-base - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. ghunti/laravel-base

ActiveLibrary[Framework](/categories/framework)

ghunti/laravel-base
===================

Some base classes and overrides for the Laravel 4 framework

v5.5.0(7y ago)7881PHPPHP &gt;=7.0.0

Since Jul 30Pushed 7y ago1 watchersCompare

[ Source](https://github.com/ghunti/laravel-base)[ Packagist](https://packagist.org/packages/ghunti/laravel-base)[ RSS](/packages/ghunti-laravel-base/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (14)Used By (0)

Laravel Base
============

[](#laravel-base)

This is a packaged that brings small improvements to the [Laravel](http://laravel.com) framework.

All the improvements were made keeping in mind the Laravel way and good development practices. If you want to contribute don't hesitate.

Installation
------------

[](#installation)

```
{
    "require": {
        "ghunti/laravel-base": "5.0.*"
    }
}
```

Add the following middleware to the app/Http/Middleware:

```
protected $middleware = [
    ......,
    'Ghunti\LaravelBase\Middleware\ShareMessagesFromSession',
];
```

Features
--------

[](#features)

### Permission Denied Exception

[](#permission-denied-exception)

[Exception/PermissionDeniedException.php](src/Exception/PermissionDeniedException.php)

I like to use exceptions on my controllers to have a cleaner code followed by a bunch of catches, so this is just an exception that I throw whenever a user doesn't have enough permissions or is not logged in.

### Validator

[](#validator)

[Validation/Validator.php](src/Validation/Validator.php)

This is an extension to the `Illuminate\Validation\Validator` and adds a single method `passOrFail`.

If the validation fails, the method will create a new `Ghunti\LaravelBase\Exception\ValidatorException` and inject itself into the exception, throwing it.

### Validator Exception

[](#validator-exception)

[Exception/ValidatorException.php](src/Exception/ValidatorException.php)

This is an exception that holds the failed validation object. The idea is to use it like this:

```
use Ghunti\LaravelBase\Exception\ValidatorException;
...
try {
    Validator::make(
        Input::all(),
        array(
            'name' => array(
            'required',
            'unique:table_name',
            ),
        )
    )->passOrFail();

} catch (ValidatorException $e) {
    return Redirect::route('creation_route')
        ->withInput()
        ->withErrors($e->getValidator());
}
```

As you can see, this ways we can retrieve the validator from the exception (`$e->getValidator()`) to use it in any way we want.

### Redirect With Messages

[](#redirect-with-messages)

I like the way Laravel redirects the [errors](http://laravel.com/docs/validation#error-messages-and-views) and makes them available on the views, so I've implemented the same logic for any message with the method `withMessages()`.

```
    return Redirect::route('some_route')
        ->withMessages(
            array('success' => 'Something worked for a change!!!')
        );
    //or
    return Redirect::route('some_route')
        ->withMessages(
            array('error' => 'Crappy as usual!')
        );
```

Check that i'm passing an array to the `withMessages()` method and I'm even specifying a type for the message so latter on the view I can do:

```
