dimanche 20 août 2017

Which controller should laravel packages extend from

Building a package for laravel 5, containing models, views & controllers. Which controller should packages generally extend from to avoid problems, if the consumer of the package, might have changed the application default namespace to something different.

I always come across tutorials and blog-posts where people use App\Http\Controllers\Controller explaining how to build a package for laravel.

namespace Devdojo\Calculator;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller; //<--- 

class CalculatorController extends Controller
{
    public function add($a, $b){
        return $a + $b;
    }

    public function subtract($a, $b){
        return $a - $b;
    }
}

I can see the benefits of using the applications controller, where the developer already may have made some adjustments, but using class PackageController extends App\Http\Controllers\Controller in a package might not be the correct solution, does it?!

The same might apply to App\Http\Requests
and to App\User (for User/Auth I found my solution here).



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2wllBvA
via IFTTT

Aucun commentaire:

Enregistrer un commentaire