PHPackages                             mmedia/classcontroller - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. mmedia/classcontroller

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

mmedia/classcontroller
======================

A controller that can take standard PHP classes and convert them to controller methods with auto validation.

1.2.1(3y ago)110.3k↓43.5%MITPHPPHP ^7.4|^8.0

Since Jul 13Pushed 3y ago1 watchersCompare

[ Source](https://github.com/M-Media-Group/Laravel-Class-Controller)[ Packagist](https://packagist.org/packages/mmedia/classcontroller)[ Docs](https://github.com/M-Media-Group/Laravel-Class-Controller)[ RSS](/packages/mmedia-classcontroller/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

Laravel ClassController
=======================

[](#laravel-classcontroller)

[![Latest Version on Packagist](https://camo.githubusercontent.com/dc96e342097e16072a4c6c13a423d52bbe9a43919278d9c79bfe8ed185de0277/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6d656469612f636c617373636f6e74726f6c6c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mmedia/classcontroller)[![Total Downloads](https://camo.githubusercontent.com/fd21d929663a4219824b7c79a6944a0067b9664c55fad8b0386cab79a0ba950b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6d656469612f636c617373636f6e74726f6c6c65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mmedia/classcontroller)[![Maintained](https://camo.githubusercontent.com/a1ba7c4c0ca8bc1b381203e471096ec30faf83259b54739cecde9fffb65a5380/68747470733a2f2f696d672e736869656c64732e696f2f6d61696e74656e616e63652f7965732f323032323f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/a1ba7c4c0ca8bc1b381203e471096ec30faf83259b54739cecde9fffb65a5380/68747470733a2f2f696d672e736869656c64732e696f2f6d61696e74656e616e63652f7965732f323032323f7374796c653d666c61742d737175617265)[![Coverage](https://camo.githubusercontent.com/a88b1df2f36d67a09cc757d035cea5bc9e9805938c88594c74a3b6aad6bf9e48/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d39332532352d677265656e2e7376673f7374796c653d666c61742d737175617265)](https://github.com/M-Media-Group/Laravel-Class-Controller/tree/master/tests/Unit)

The ClassController extends the basic Controller and allows you to use defined PHP class methods directly as controller methods.

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

[](#installation)

You can install the package via composer:

```
composer require mmedia/classcontroller
```

Usage
-----

[](#usage)

See the [`Test::class`](https://github.com/M-Media-Group/Laravel-Class-Controller/blob/master/examples/Test.php) that this example is using.

```
use MMedia\ClassController\Http\Controllers\ClassController;

class TestClassController extends ClassController
{
    protected $inheritedClass = 'MMedia\ClassController\Examples\Test';

    //Done. All methods from the class Test are inherited and wrapped in Laravel validation automatically
}
```

When you extend a `ClassController` and give your new controller a name like `{inheritedClass}ClassController`, all of the methods of `{inheritedClass}` are inherited and wrapped with Laravel validation rules and responses. If you need a namespaced class, you can use [`inheritedClass`](#inheritedclass) property to specify a class with its namespace instead.

In your routes, you can now call all the methods of the inheritedClass, [`Test::class`](https://github.com/M-Media-Group/Laravel-Class-Controller/blob/master/examples/Test.php) in this case, directly:

```
// We're just using the methods in the inherited class methods directly
Route::get('/noParams', [TestClassController::class, 'noParams']); // === \Test::noParams()
Route::get('/mixedParam/{param}', [TestClassController::class, 'mixedParam']); // === \Test::mixedParam($param) + auto validation!
```

Here is the equivalent when extending the default Controller insteadIn a `ClassController`, all this code is auto handled for you! ```
