Skip to content

Instantly share code, notes, and snippets.

@DuckThom
Last active July 25, 2017 09:32
Show Gist options
  • Save DuckThom/4fd72bac11b3799cd3a82ca89027512a to your computer and use it in GitHub Desktop.
Save DuckThom/4fd72bac11b3799cd3a82ca89027512a to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use App\Services\Interfaces\ExportServiceInterface as ExportService;
class ExportController extends Controller
{
protected $es;
public function __construct(ExportService $es)
{
$this->es = $es;
}
public function exportRegistrations()
{
$data = $this->es->registrations();
/* Do stuff with the data */
return; // Return a response
}
}
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Services\Interfaces\ExportServiceInterface as ExportService;
class ExportRegistrationsCommand extends Command
{
protected $es;
protected $signature = 'export:registrations';
public function __construct(ExportService $es)
{
$this->es = $es;
}
public function handle()
{
$data = $this->es->registrations();
/* Do stuff with the data */
}
}
<?php
namespace App\Services;
use App\Services\Interfaces\ExportServiceInterface;
class ExportService implements ExportServiceInterface
{
public function registrations()
{
$data = [];
/* Do the query stuff */
return $data;
}
}
<?php
namespace App\Services\Interfaces;
interface ExportServiceInterface
{
public function registrations();
}
<?php
namespace App\Providers;
use App\Services\ExportService;
use Illuminate\Support\ServiceProvider;
use App\Services\Interfaces\ExportServiceInterface;
class ExportServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind(ExportServiceInterface::class, ExportService::class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment