├── LICENSE ├── README.md ├── composer.json └── src ├── .gitkeep ├── Quick.php ├── ViewResolver.php └── helpers.php /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Armands Leinieks 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Opinionated quick return for views in Laravel 5 2 | 3 | Are you tired of typing out view name for your controllers? Then this package is for you! 4 | 5 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) 6 | [![Build Status](https://img.shields.io/travis/armandsar/laravel-quick-view/master.svg?style=flat-square)](https://travis-ci.org/armandsar/laravel-quick-view) 7 | [![Total Downloads](https://img.shields.io/packagist/dt/armandsar/laravel-quick-view.svg?style=flat-square)](https://packagist.org/packages/armandsar/laravel-quick-view) 8 | 9 | ## Install 10 | 11 | Via Composer 12 | 13 | ``` bash 14 | $ composer require armandsar/laravel-quick-view 15 | ``` 16 | 17 | 18 | ## Usage 19 | 20 | Namespace and controller name as folders and method name as file name. 21 | 22 | Given that we have a Admin/UsersController 23 | 24 | ``` php 25 | public function create() 26 | { 27 | return quick(); 28 | } 29 | ``` 30 | 31 | would assume a view at **admin/users/create.blade.php** 32 | 33 | 34 | Or if you prefer not to use a helper, there is also a trait: 35 | 36 | 37 | ``` php 38 | class UsersController 39 | { 40 | use Armandsar\QuickView\Quick; 41 | 42 | public function show($id) 43 | { 44 | $user = User::findOrFail($id) 45 | return $this->quick(['user' => $user]); 46 | } 47 | } 48 | 49 | ``` 50 | 51 | would assume a view at **admin/users/show.blade.php** 52 | 53 | ## Testing 54 | 55 | ``` bash 56 | $ phpunit 57 | ``` 58 | 59 | ## License 60 | 61 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "armandsar/laravel-quick-view", 3 | "description": "Quickly render view from controller without typing file names", 4 | "keywords": [ 5 | "laravel", 6 | "view" 7 | ], 8 | "homepage": "https://github.com/armandsar/laravel-quick-view", 9 | "license": "MIT", 10 | "authors": [ 11 | { 12 | "name": "Armands Leinieks", 13 | "email": "armands.leinieks@gmail.com" 14 | } 15 | ], 16 | "require": { 17 | "php": ">=7.0.0", 18 | "laravel/framework": "~5.1" 19 | }, 20 | "require-dev": { 21 | "phpunit/phpunit": "~6.0||~7.0", 22 | "orchestra/testbench": "~3.0", 23 | "mockery/mockery": "0.9.*" 24 | }, 25 | "autoload": { 26 | "psr-4": { 27 | "Armandsar\\QuickView\\": "src/" 28 | }, 29 | "files": [ 30 | "src/helpers.php" 31 | ] 32 | }, 33 | "autoload-dev": { 34 | "psr-4": { 35 | "Armandsar\\QuickView\\Tests\\": "tests/" 36 | } 37 | }, 38 | "minimum-stability": "dev" 39 | } 40 | -------------------------------------------------------------------------------- /src/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/armandsar/laravel-quick-view/0e0389d18b71c0bed1cf7a7bbfe69c8b93b219a2/src/.gitkeep -------------------------------------------------------------------------------- /src/Quick.php: -------------------------------------------------------------------------------- 1 | call(); 10 | } 11 | } -------------------------------------------------------------------------------- /src/ViewResolver.php: -------------------------------------------------------------------------------- 1 | data = $data; 17 | $this->mergeData = $mergeData; 18 | } 19 | 20 | public function call() 21 | { 22 | $trace = array_last(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3)); 23 | 24 | $class = $trace['class']; 25 | $method = snake_case($trace['function']); 26 | 27 | $class = str_replace("App\\Http\\Controllers\\", '', $class); 28 | $class = preg_replace('/Controller$/', '', $class); 29 | $class = snake_case($class); 30 | $class = str_replace('\\_', '.', $class); 31 | 32 | $view = $class . '.' . $method; 33 | 34 | return $this->viewFactory()->make($view, $this->data, $this->mergeData); 35 | } 36 | 37 | /** 38 | * @return ViewFactory 39 | */ 40 | private function viewFactory() 41 | { 42 | return app(ViewFactory::class); 43 | } 44 | } -------------------------------------------------------------------------------- /src/helpers.php: -------------------------------------------------------------------------------- 1 | call(); 8 | } 9 | } --------------------------------------------------------------------------------