Common usage for Multimedia Street Projects

v0.1.3 2016-06-07 17:35 UTC

This package is not auto-updated.

Last update: 2024-11-09 19:45:44 UTC


README

Latest Version on Packagist Software License Laravel Total Downloads

Some boilerplate for most of the Multimedia Street projects.

Table of Contents

Included Packages

  • Image - PHP Image Manipulation
  • Image (Cache) - Caching extension for the Intervention Image Class
  • iSeed - Inverse seed generator
  • Whoops - PHP errors for cool kids
  • Clockwork - Chrome extension for PHP development
  • DOMPDF - DOMPDF Wrapper for Laravel 5
  • Excel - Laravel Excel v2.1.* for Laravel 5
  • CORS - CORS in Laravel 5

Install

Via Composer

Require the multimedia-street/common package in your composer.json and update your dependencies.

$ composer require multimedia-street/common

Add Service Provider

Include the Service Provider to your config/app.php in providers array

Mmstreet\Common\ServiceProvider::class,

Add Package Facades

Include Facades to your config/app.php in aliases array

'Excel' => Maatwebsite\Excel\Facades\Excel::class,
'PDF' => Barryvdh\DomPDF\Facade::class,
'Image' => Intervention\Image\Facades\Image::class,

Disabling CSRF protection for your API

To use the CORS properly, as stated in the documentation, in App\Http\Middleware\VerifyCsrfToken, add your routes to the exceptions:

protected $except = [
  'api/*'
];

Post Install

Publish Packages Configurations

After the installation is completed, publish the vendor publish by running:

php artisan vendor:publish

Extend Exception Handler

You can use the Exception handler specially for developing. This includes the Whoops. You can extend your app/Exceptions/Handler.php with Mmstreet\Common\Exceptions\Handler. Also add your uris using the $corsUris property to be used in CORS. See example below.

namespace App\Exceptions;

use Mmstreet\Common\Exceptions\Handler as ExceptionHandler;

class Handler extends ExceptionHandler
{
    protected $corsUris = [
        'api/*', // default
        'auth/*',
        'logout'
    ];
}

Response Trait

You can use the Mmstreet\Common\Traits\ResponseTrait to your App\Http\Controllers\Controller for easy returning response either Json or in View. See example below.

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Mmstreet\Common\Traits\ResponseTrait;

abstract class Controller extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests, ResponseTrait;
}

Example usage:

namespace App\Http\Controllers;

use App\Post;

class PostController extends Controller
{
    public function index()
    {
        $posts = Post::all();

        if ($posts->isEmpty()) {
            // {The message}, {The data}, {status code}, {view name}, {response headers}, {Json callback}
            return $this->errorResponse('No Posts as of the moment', $posts, 404, 404, [], 'callback');
        }

        return $this->successResponse('Successfully get all posts', $posts);
    }

    public function all()
    {
        $posts = Post::all();

        if ($post->isEmpty()) {
            // You can also use Closure.
            return $this->errorResponse(function() {
                return response('No POSTS');
            }
        }

        return $this->successResponse('Successfully get all posts', $posts);
    }
}

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email :author_email instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.