Some boilerplate for most of the Multimedia Street projects.
- Included Packages
- Install
- Via Composer
- Add Service Provider
- Add Package Facades
- Disabling CSRF protection for your API
- Post Install
- Publish Packages Configurations
- Extend Exception Handler
- Response Trait
- Change Log
- Testing
- Contributing
- Security
- Credits
- License
- 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
Require the multimedia-street/common
package in your composer.json and update your dependencies.
$ composer require multimedia-street/common
Include the Service Provider to your config/app.php
in providers array
Mmstreet\Common\ServiceProvider::class,
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,
To use the CORS properly, as stated in the documentation, in App\Http\Middleware\VerifyCsrfToken
, add your routes to the exceptions:
protected $except = [
'api/*'
];
After the installation is completed, publish the vendor publish by running:
php artisan vendor:publish
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'
];
}
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);
}
}
Please see CHANGELOG for more information what has changed recently.
$ composer test
Please see CONTRIBUTING and CONDUCT for details.
If you discover any security related issues, please email :author_email instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.