class SomeController extends Controller { public function doALot(Request $request) { $this -> doOne($someOtherVariable);
So, how to call doOne() from doALot() without passing the embedded resource, but having Request in doOne() ? It seems like bad practice goes through $request everywhere.
Solution tl; dr is impossible, but there are other ways - read a short answer from Alexei Mezenin
Long version (maybe not the best, but enough).
$ php artisan make:provider SomeServiceProvider
Then, in the created provider, edit register() calling something along the lines of:
public function register() { $this -> app -> bind('App\Services\SomeService', function ($app) { return new SomeService(); }); }
Then, go on to create a service class to which the resource attribute will be added.
<?php namespace App\Services; use \Illuminate\Support\Facades\Request; class SomeService { private $request; public function __construct(Request $request) { $this -> request = $request; } public function doOne($someOtherVariable) {} }
Then move your methods from the controller for maintenance and instead add the service to the controller.
Trade-offs: (-) two useless files to perform basic functions, (+) separate the logical implementation from the controller, (~), probably more clean code.
source share