Last active
April 18, 2020 17:34
-
-
Save TiagoSilvaPereira/931f55f661704103b2aa2a54bc207944 to your computer and use it in GitHub Desktop.
AbstractCrudController 02
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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