Skip to content

Instantly share code, notes, and snippets.

@TiagoSilvaPereira
Last active April 18, 2020 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TiagoSilvaPereira/931f55f661704103b2aa2a54bc207944 to your computer and use it in GitHub Desktop.
Save TiagoSilvaPereira/931f55f661704103b2aa2a54bc207944 to your computer and use it in GitHub Desktop.
AbstractCrudController 02
<?php
namespace App\Http\Controllers\Base;
use ReflectionClass;
use Illuminate\Support\Str;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
abstract class CrudController extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected function getRouteName()
{
return $this->getViewsFolderName();
}
protected function getViewsFolderName()
{
$name = $this->getCollectionName();
return Str::kebab($name);
}
protected function getCollectionName()
{
$name = $this->getModelName();
$pluralName = Str::plural($name);
return Str::camel($pluralName);
}
protected function getModelName()
{
$reflection = new ReflectionClass($this->model);
return $reflection->getShortName();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment