├── .env.example ├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── app ├── Authorizable.php ├── Console │ ├── Commands │ │ └── AuthPermissionCommand.php │ └── Kernel.php ├── Exceptions │ └── Handler.php ├── Http │ ├── Controllers │ │ ├── Auth │ │ │ ├── ForgotPasswordController.php │ │ │ ├── LoginController.php │ │ │ ├── RegisterController.php │ │ │ └── ResetPasswordController.php │ │ ├── Controller.php │ │ ├── HomeController.php │ │ ├── PostController.php │ │ ├── RoleController.php │ │ └── UserController.php │ ├── Kernel.php │ └── Middleware │ │ ├── EncryptCookies.php │ │ ├── RedirectIfAuthenticated.php │ │ ├── TrimStrings.php │ │ └── VerifyCsrfToken.php ├── Permission.php ├── Post.php ├── Providers │ ├── AppServiceProvider.php │ ├── AuthServiceProvider.php │ ├── BroadcastServiceProvider.php │ ├── EventServiceProvider.php │ └── RouteServiceProvider.php ├── Role.php └── User.php ├── artisan ├── bootstrap ├── app.php ├── autoload.php └── cache │ └── .gitignore ├── composer.json ├── composer.lock ├── config ├── app.php ├── auth.php ├── broadcasting.php ├── cache.php ├── database.php ├── filesystems.php ├── mail.php ├── queue.php ├── services.php ├── session.php └── view.php ├── database ├── .gitignore ├── factories │ └── ModelFactory.php ├── migrations │ ├── 2014_10_12_000000_create_users_table.php │ ├── 2014_10_12_100000_create_password_resets_table.php │ ├── 2017_04_30_012311_create_posts_table.php │ └── 2017_04_30_014352_create_permission_tables.php └── seeds │ └── DatabaseSeeder.php ├── package.json ├── phpunit.xml ├── public ├── .htaccess ├── css │ ├── app.css │ └── fonts │ │ ├── glyphicons-halflings-regular.eot │ │ ├── glyphicons-halflings-regular.svg │ │ ├── glyphicons-halflings-regular.ttf │ │ ├── glyphicons-halflings-regular.woff │ │ └── glyphicons-halflings-regular.woff2 ├── favicon.ico ├── index.php ├── js │ ├── app.js │ └── particlesjs-config.json └── robots.txt ├── resources ├── assets │ ├── js │ │ ├── app.js │ │ ├── bootstrap.js │ │ └── components │ │ │ └── Example.vue │ └── sass │ │ ├── _variables.scss │ │ └── app.scss ├── lang │ └── en │ │ ├── auth.php │ │ ├── pagination.php │ │ ├── passwords.php │ │ └── validation.php └── views │ ├── auth │ ├── login.blade.php │ ├── passwords │ │ ├── email.blade.php │ │ └── reset.blade.php │ └── register.blade.php │ ├── home.blade.php │ ├── layouts │ └── app.blade.php │ ├── post │ ├── _form.blade.php │ ├── edit.blade.php │ ├── index.blade.php │ └── new.blade.php │ ├── role │ └── index.blade.php │ ├── shared │ ├── _actions.blade.php │ └── _permissions.blade.php │ ├── user │ ├── _form.blade.php │ ├── edit.blade.php │ ├── index.blade.php │ └── new.blade.php │ └── welcome.blade.php ├── routes ├── api.php ├── channels.php ├── console.php └── web.php ├── server.php ├── storage ├── app │ ├── .gitignore │ └── public │ │ └── .gitignore ├── framework │ ├── .gitignore │ ├── cache │ │ └── .gitignore │ ├── sessions │ │ └── .gitignore │ ├── testing │ │ └── .gitignore │ └── views │ │ └── .gitignore └── logs │ └── .gitignore ├── tests ├── CreatesApplication.php ├── Feature │ └── ExampleTest.php ├── TestCase.php └── Unit │ └── ExampleTest.php ├── webpack.mix.js └── yarn.lock /.env.example: -------------------------------------------------------------------------------- 1 | APP_NAME=Laravel 2 | APP_ENV=local 3 | APP_KEY= 4 | APP_DEBUG=true 5 | APP_LOG_LEVEL=debug 6 | APP_URL=http://localhost 7 | 8 | DB_CONNECTION=mysql 9 | DB_HOST=127.0.0.1 10 | DB_PORT=3306 11 | DB_DATABASE=homestead 12 | DB_USERNAME=homestead 13 | DB_PASSWORD=secret 14 | 15 | BROADCAST_DRIVER=log 16 | CACHE_DRIVER=file 17 | SESSION_DRIVER=file 18 | QUEUE_DRIVER=sync 19 | 20 | REDIS_HOST=127.0.0.1 21 | REDIS_PASSWORD=null 22 | REDIS_PORT=6379 23 | 24 | MAIL_DRIVER=smtp 25 | MAIL_HOST=smtp.mailtrap.io 26 | MAIL_PORT=2525 27 | MAIL_USERNAME=null 28 | MAIL_PASSWORD=null 29 | MAIL_ENCRYPTION=null 30 | 31 | PUSHER_APP_ID= 32 | PUSHER_APP_KEY= 33 | PUSHER_APP_SECRET= 34 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | *.css linguist-vendored 3 | *.scss linguist-vendored 4 | *.js linguist-vendored 5 | CHANGELOG.md export-ignore 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /public/hot 3 | /public/storage 4 | /storage/*.key 5 | /vendor 6 | /.idea 7 | /.vagrant 8 | Homestead.json 9 | Homestead.yaml 10 | npm-debug.log 11 | .env 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Mohd. Saqueib Ansari 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Roles Permissions Laravel (RPL) 2 | A stater kit with Roles and Permissions implementation on Laravel 5.4 3 | 4 | ### Install 5 | 1. To use it just clone the repo and composer install. 6 | 2. Set the database connection 7 | 3. To test the app run `php artisan db:seed`, our [interactive seeder](http://www.qcode.in/advance-interactive-database-seeding-in-laravel/) will take care of everything. 8 | 9 | ### Add a new Resource 10 | 1. Create desired resource by running 11 | ```bash 12 | ## Create Comment model with migration and resource controller 13 | php artisan make:model Comment -mcr 14 | ``` 15 | 2. Register route for it. 16 | ```php 17 | Route::group( ['middleware' => ['auth']], function() { 18 | ... 19 | Route::resource('comments', 'CommentController'); 20 | }); 21 | ``` 22 | 23 | 3. Now implement your controllers methods and use the `Authorizable` trait 24 | ```php 25 | use App\Authorizable; 26 | 27 | class CommentController extends Controller 28 | { 29 | use Authorizable; 30 | ... 31 | ``` 32 | 33 | 4. Now add the permissions for this new `Comment` model. 34 | ```bash 35 | php artisan auth:permission Comment 36 | ``` 37 | 38 | That's it, you have added new resource controller which have full access control by laravel permissions. 39 | 40 | ### auth:permission command 41 | This command can be user to add or remove permission for a given model 42 | 43 | ```bash 44 | ## add permission 45 | php artisan auth:permission Comment 46 | 47 | ## remove permissions 48 | php artisan auth:permission Comment --remove 49 | ``` 50 | 51 | ### Author 52 | Created by [QCode.in](http://www.qcode.in) 53 | 54 | ## License 55 | 56 | [MIT license](http://opensource.org/licenses/MIT). 57 | -------------------------------------------------------------------------------- /app/Authorizable.php: -------------------------------------------------------------------------------- 1 | 'view', 17 | 'edit' => 'edit', 18 | 'show' => 'view', 19 | 'update' => 'edit', 20 | 'create' => 'add', 21 | 'store' => 'add', 22 | 'destroy' => 'delete' 23 | ]; 24 | 25 | /** 26 | * Override of callAction to perform the authorization before it calls the action 27 | * 28 | * @param $method 29 | * @param $parameters 30 | * @return mixed 31 | */ 32 | public function callAction($method, $parameters) 33 | { 34 | if( $ability = $this->getAbility($method) ) { 35 | $this->authorize($ability); 36 | } 37 | 38 | return parent::callAction($method, $parameters); 39 | } 40 | 41 | /** 42 | * Get ability 43 | * 44 | * @param $method 45 | * @return null|string 46 | */ 47 | public function getAbility($method) 48 | { 49 | $routeName = explode('.', \Request::route()->getName()); 50 | $action = array_get($this->getAbilities(), $method); 51 | 52 | return $action ? $action . '_' . $routeName[0] : null; 53 | } 54 | 55 | /** 56 | * @return array 57 | */ 58 | private function getAbilities() 59 | { 60 | return $this->abilities; 61 | } 62 | 63 | /** 64 | * @param array $abilities 65 | */ 66 | public function setAbilities($abilities) 67 | { 68 | $this->abilities = $abilities; 69 | } 70 | } -------------------------------------------------------------------------------- /app/Console/Commands/AuthPermissionCommand.php: -------------------------------------------------------------------------------- 1 | generatePermissions(); 42 | 43 | // check if its remove 44 | if( $is_remove = $this->option('remove') ) { 45 | // remove permission 46 | if( Permission::where('name', 'LIKE', '%'. $this->getNameArgument())->delete() ) { 47 | $this->warn('Permissions ' . implode(', ', $permissions) . ' deleted.'); 48 | } else { 49 | $this->warn('No permissions for ' . $this->getNameArgument() .' found!'); 50 | } 51 | 52 | } else { 53 | // create permissions 54 | foreach ($permissions as $permission) { 55 | Permission::firstOrCreate(['name' => $permission ]); 56 | } 57 | 58 | $this->info('Permissions ' . implode(', ', $permissions) . ' created.'); 59 | } 60 | 61 | // sync role for admin 62 | if( $role = Role::where('name', 'Admin')->first() ) { 63 | $role->syncPermissions(Permission::all()); 64 | 65 | $this->info('Admin permissions updated.'); 66 | } 67 | } 68 | 69 | 70 | /** 71 | * Build permissions from name 72 | * 73 | * @return array 74 | */ 75 | private function generatePermissions() 76 | { 77 | $abilities = ['view', 'add', 'edit', 'delete']; 78 | $name = $this->getNameArgument(); 79 | 80 | return array_map(function($val) use ($name) { 81 | return $val . '_'. $name; 82 | }, $abilities); 83 | } 84 | 85 | /** 86 | * Get pluralized name argument 87 | * 88 | * @return string 89 | */ 90 | private function getNameArgument() 91 | { 92 | return strtolower(str_plural($this->argument('name'))); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /app/Console/Kernel.php: -------------------------------------------------------------------------------- 1 | command('inspire') 29 | // ->hourly(); 30 | } 31 | 32 | /** 33 | * Register the Closure based commands for the application. 34 | * 35 | * @return void 36 | */ 37 | protected function commands() 38 | { 39 | require base_path('routes/console.php'); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/Exceptions/Handler.php: -------------------------------------------------------------------------------- 1 | unauthorized($request, $exception); 50 | // } 51 | 52 | return parent::render($request, $exception); 53 | } 54 | 55 | /** 56 | * Convert an authentication exception into an unauthenticated response. 57 | * 58 | * @param \Illuminate\Http\Request $request 59 | * @param \Illuminate\Auth\AuthenticationException $exception 60 | * @return \Illuminate\Http\Response 61 | */ 62 | protected function unauthenticated($request, AuthenticationException $exception) 63 | { 64 | if ($request->expectsJson()) { 65 | return response()->json(['error' => 'Unauthenticated.'], 401); 66 | } 67 | 68 | return redirect()->guest(route('login')); 69 | } 70 | 71 | /** 72 | * Handle unauthorized response 73 | * 74 | * @param $request 75 | * @param Exception $exception 76 | * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse 77 | */ 78 | private function unauthorized($request, Exception $exception) 79 | { 80 | if ($request->expectsJson()) { 81 | return response()->json(['error' => $exception->getMessage()], 403); 82 | } 83 | 84 | flash()->warning($exception->getMessage()); 85 | return redirect()->route('home'); 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ForgotPasswordController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/LoginController.php: -------------------------------------------------------------------------------- 1 | middleware('guest')->except('logout'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/RegisterController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 40 | } 41 | 42 | /** 43 | * Get a validator for an incoming registration request. 44 | * 45 | * @param array $data 46 | * @return \Illuminate\Contracts\Validation\Validator 47 | */ 48 | protected function validator(array $data) 49 | { 50 | return Validator::make($data, [ 51 | 'name' => 'required|string|max:255', 52 | 'email' => 'required|string|email|max:255|unique:users', 53 | 'password' => 'required|string|min:6|confirmed', 54 | ]); 55 | } 56 | 57 | /** 58 | * Create a new user instance after a valid registration. 59 | * 60 | * @param array $data 61 | * @return User 62 | */ 63 | protected function create(array $data) 64 | { 65 | $user = User::create([ 66 | 'name' => $data['name'], 67 | 'email' => $data['email'], 68 | 'password' => bcrypt($data['password']), 69 | ]); 70 | 71 | // assign user role 72 | $user->assignRole('User'); 73 | 74 | return $user; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/ResetPasswordController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/Http/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | middleware('auth'); 18 | } 19 | 20 | /** 21 | * Show the application dashboard. 22 | * 23 | * @return \Illuminate\Http\Response 24 | */ 25 | public function index() 26 | { 27 | return view('home'); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /app/Http/Controllers/PostController.php: -------------------------------------------------------------------------------- 1 | with('user')->paginate(); 22 | return view('post.index', compact('result')); 23 | } 24 | 25 | /** 26 | * Show the form for creating a new resource. 27 | * 28 | * @return \Illuminate\Http\Response 29 | */ 30 | public function create() 31 | { 32 | return view('post.new'); 33 | } 34 | 35 | /** 36 | * Store a newly created resource in storage. 37 | * 38 | * @param \Illuminate\Http\Request $request 39 | * @return \Illuminate\Http\Response 40 | */ 41 | public function store(Request $request) 42 | { 43 | $this->validate($request, [ 44 | 'title' => 'required|min:10', 45 | 'body' => 'required|min:20' 46 | ]); 47 | 48 | $request->user()->posts()->create($request->all()); 49 | 50 | flash('Post has been added'); 51 | 52 | return redirect()->back(); 53 | } 54 | 55 | /** 56 | * Display the specified resource. 57 | * 58 | * @param \App\Post $post 59 | * @return \Illuminate\Http\Response 60 | */ 61 | public function show(Post $post) 62 | { 63 | // 64 | } 65 | 66 | /** 67 | * Show the form for editing the specified resource. 68 | * 69 | * @param \App\Post $post 70 | * @return \Illuminate\Http\Response 71 | */ 72 | public function edit(Post $post) 73 | { 74 | $post = Post::findOrFail($post->id); 75 | 76 | return view('post.edit', compact('post')); 77 | } 78 | 79 | /** 80 | * Update the specified resource in storage. 81 | * 82 | * @param \Illuminate\Http\Request $request 83 | * @param \App\Post $post 84 | * @return \Illuminate\Http\Response 85 | */ 86 | public function update(Request $request, Post $post) 87 | { 88 | $this->validate($request, [ 89 | 'title' => 'required|min:10', 90 | 'body' => 'required|min:20' 91 | ]); 92 | 93 | $me = $request->user(); 94 | 95 | if( $me->hasRole('Admin') ) { 96 | $post = Post::findOrFail($post->id); 97 | } else { 98 | $post = $me->posts()->findOrFail($post->id); 99 | } 100 | 101 | $post->update($request->all()); 102 | 103 | flash()->success('Post has been updated.'); 104 | 105 | return redirect()->route('posts.index'); 106 | } 107 | 108 | /** 109 | * Remove the specified resource from storage. 110 | * 111 | * @param \App\Post $post 112 | * @return \Illuminate\Http\Response 113 | */ 114 | public function destroy(Post $post) 115 | { 116 | $me = Auth::user(); 117 | 118 | if( $me->hasRole('Admin') ) { 119 | $post = Post::findOrFail($post->id); 120 | } else { 121 | $post = $me->posts()->findOrFail($post->id); 122 | } 123 | 124 | $post->delete(); 125 | 126 | flash()->success('Post has been deleted.'); 127 | 128 | return redirect()->route('posts.index'); 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /app/Http/Controllers/RoleController.php: -------------------------------------------------------------------------------- 1 | validate($request, ['name' => 'required|unique:roles']); 36 | 37 | if( Role::create($request->only('name')) ) { 38 | flash('Role Added'); 39 | } 40 | 41 | return redirect()->back(); 42 | } 43 | 44 | /** 45 | * Update the specified resource in storage. 46 | * 47 | * @param \Illuminate\Http\Request $request 48 | * @param int $id 49 | * @return \Illuminate\Http\Response 50 | */ 51 | public function update(Request $request, $id) 52 | { 53 | if($role = Role::findOrFail($id)) { 54 | // admin role has everything 55 | if($role->name === 'Admin') { 56 | $role->syncPermissions(Permission::all()); 57 | return redirect()->route('roles.index'); 58 | } 59 | 60 | $permissions = $request->get('permissions', []); 61 | 62 | $role->syncPermissions($permissions); 63 | 64 | flash( $role->name . ' permissions has been updated.'); 65 | } else { 66 | flash()->error( 'Role with id '. $id .' note found.'); 67 | } 68 | 69 | return redirect()->route('roles.index'); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /app/Http/Controllers/UserController.php: -------------------------------------------------------------------------------- 1 | paginate(); 24 | 25 | return view('user.index', compact('result')); 26 | } 27 | 28 | /** 29 | * Show the form for creating a new resource. 30 | * 31 | * @return \Illuminate\Http\Response 32 | */ 33 | public function create() 34 | { 35 | $roles = Role::pluck('name', 'id'); 36 | 37 | return view('user.new', compact('roles')); 38 | } 39 | 40 | /** 41 | * Store a newly created resource in storage. 42 | * 43 | * @param \Illuminate\Http\Request $request 44 | * @return \Illuminate\Http\Response 45 | */ 46 | public function store(Request $request) 47 | { 48 | $this->validate($request, [ 49 | 'name' => 'bail|required|min:2', 50 | 'email' => 'required|email|unique:users', 51 | 'password' => 'required|min:6', 52 | 'roles' => 'required|min:1' 53 | ]); 54 | 55 | // hash password 56 | $request->merge(['password' => bcrypt($request->get('password'))]); 57 | 58 | // Create the user 59 | if ( $user = User::create($request->except('roles', 'permissions')) ) { 60 | 61 | $this->syncPermissions($request, $user); 62 | 63 | flash('User has been created.'); 64 | 65 | } else { 66 | flash()->error('Unable to create user.'); 67 | } 68 | 69 | return redirect()->route('users.index'); 70 | } 71 | 72 | /** 73 | * Display the specified resource. 74 | * 75 | * @param int $id 76 | * @return \Illuminate\Http\Response 77 | */ 78 | public function show($id) 79 | { 80 | // 81 | } 82 | 83 | /** 84 | * Show the form for editing the specified resource. 85 | * 86 | * @param int $id 87 | * @return \Illuminate\Http\Response 88 | */ 89 | public function edit($id) 90 | { 91 | $user = User::find($id); 92 | $roles = Role::pluck('name', 'id'); 93 | $permissions = Permission::all('name', 'id'); 94 | 95 | return view('user.edit', compact('user', 'roles', 'permissions')); 96 | } 97 | 98 | /** 99 | * Update the specified resource in storage. 100 | * 101 | * @param \Illuminate\Http\Request $request 102 | * @param int $id 103 | * @return \Illuminate\Http\Response 104 | */ 105 | public function update(Request $request, $id) 106 | { 107 | $this->validate($request, [ 108 | 'name' => 'bail|required|min:2', 109 | 'email' => 'required|email|unique:users,email,' . $id, 110 | 'roles' => 'required|min:1' 111 | ]); 112 | 113 | // Get the user 114 | $user = User::findOrFail($id); 115 | 116 | // Update user 117 | $user->fill($request->except('roles', 'permissions', 'password')); 118 | 119 | // check for password change 120 | if($request->get('password')) { 121 | $user->password = bcrypt($request->get('password')); 122 | } 123 | 124 | // Handle the user roles 125 | $this->syncPermissions($request, $user); 126 | 127 | $user->save(); 128 | 129 | flash()->success('User has been updated.'); 130 | 131 | return redirect()->route('users.index'); 132 | } 133 | 134 | /** 135 | * Remove the specified resource from storage. 136 | * 137 | * @param int $id 138 | * @return \Illuminate\Http\Response 139 | * @internal param Request $request 140 | */ 141 | public function destroy($id) 142 | { 143 | if ( Auth::user()->id == $id ) { 144 | flash()->warning('Deletion of currently logged in user is not allowed :(')->important(); 145 | return redirect()->back(); 146 | } 147 | 148 | if( User::findOrFail($id)->delete() ) { 149 | flash()->success('User has been deleted'); 150 | } else { 151 | flash()->success('User not deleted'); 152 | } 153 | 154 | return redirect()->back(); 155 | } 156 | 157 | /** 158 | * Sync roles and permissions 159 | * 160 | * @param Request $request 161 | * @param $user 162 | * @return string 163 | */ 164 | private function syncPermissions(Request $request, $user) 165 | { 166 | // Get the submitted roles 167 | $roles = $request->get('roles', []); 168 | $permissions = $request->get('permissions', []); 169 | 170 | // Get the roles 171 | $roles = Role::find($roles); 172 | 173 | // check for current role changes 174 | if( ! $user->hasAllRoles( $roles ) ) { 175 | // reset all direct permissions for user 176 | $user->permissions()->sync([]); 177 | } else { 178 | // handle permissions 179 | $user->syncPermissions($permissions); 180 | } 181 | 182 | $user->syncRoles($roles); 183 | 184 | return $user; 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /app/Http/Kernel.php: -------------------------------------------------------------------------------- 1 | [ 30 | \App\Http\Middleware\EncryptCookies::class, 31 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 32 | \Illuminate\Session\Middleware\StartSession::class, 33 | // \Illuminate\Session\Middleware\AuthenticateSession::class, 34 | \Illuminate\View\Middleware\ShareErrorsFromSession::class, 35 | \App\Http\Middleware\VerifyCsrfToken::class, 36 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 37 | ], 38 | 39 | 'api' => [ 40 | 'throttle:60,1', 41 | 'bindings', 42 | ], 43 | ]; 44 | 45 | /** 46 | * The application's route middleware. 47 | * 48 | * These middleware may be assigned to groups or used individually. 49 | * 50 | * @var array 51 | */ 52 | protected $routeMiddleware = [ 53 | 'auth' => \Illuminate\Auth\Middleware\Authenticate::class, 54 | 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 55 | 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 56 | 'can' => \Illuminate\Auth\Middleware\Authorize::class, 57 | 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, 58 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 59 | ]; 60 | } 61 | -------------------------------------------------------------------------------- /app/Http/Middleware/EncryptCookies.php: -------------------------------------------------------------------------------- 1 | check()) { 21 | return redirect('/home'); 22 | } 23 | 24 | return $next($request); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/Http/Middleware/TrimStrings.php: -------------------------------------------------------------------------------- 1 | belongsTo(User::class); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | 'App\Policies\ModelPolicy', 17 | ]; 18 | 19 | /** 20 | * Register any authentication / authorization services. 21 | * 22 | * @return void 23 | */ 24 | public function boot() 25 | { 26 | $this->registerPolicies(); 27 | 28 | // 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/Providers/BroadcastServiceProvider.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'App\Listeners\EventListener', 18 | ], 19 | ]; 20 | 21 | /** 22 | * Register any events for your application. 23 | * 24 | * @return void 25 | */ 26 | public function boot() 27 | { 28 | parent::boot(); 29 | 30 | // 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Providers/RouteServiceProvider.php: -------------------------------------------------------------------------------- 1 | mapApiRoutes(); 39 | 40 | $this->mapWebRoutes(); 41 | 42 | // 43 | } 44 | 45 | /** 46 | * Define the "web" routes for the application. 47 | * 48 | * These routes all receive session state, CSRF protection, etc. 49 | * 50 | * @return void 51 | */ 52 | protected function mapWebRoutes() 53 | { 54 | Route::middleware('web') 55 | ->namespace($this->namespace) 56 | ->group(base_path('routes/web.php')); 57 | } 58 | 59 | /** 60 | * Define the "api" routes for the application. 61 | * 62 | * These routes are typically stateless. 63 | * 64 | * @return void 65 | */ 66 | protected function mapApiRoutes() 67 | { 68 | Route::prefix('api') 69 | ->middleware('api') 70 | ->namespace($this->namespace) 71 | ->group(base_path('routes/api.php')); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /app/Role.php: -------------------------------------------------------------------------------- 1 | hasMany(Post::class); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /artisan: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | make(Illuminate\Contracts\Console\Kernel::class); 32 | 33 | $status = $kernel->handle( 34 | $input = new Symfony\Component\Console\Input\ArgvInput, 35 | new Symfony\Component\Console\Output\ConsoleOutput 36 | ); 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Shutdown The Application 41 | |-------------------------------------------------------------------------- 42 | | 43 | | Once Artisan has finished running, we will fire off the shutdown events 44 | | so that any final work may be done by the application before we shut 45 | | down the process. This is the last thing to happen to the request. 46 | | 47 | */ 48 | 49 | $kernel->terminate($input, $status); 50 | 51 | exit($status); 52 | -------------------------------------------------------------------------------- /bootstrap/app.php: -------------------------------------------------------------------------------- 1 | singleton( 30 | Illuminate\Contracts\Http\Kernel::class, 31 | App\Http\Kernel::class 32 | ); 33 | 34 | $app->singleton( 35 | Illuminate\Contracts\Console\Kernel::class, 36 | App\Console\Kernel::class 37 | ); 38 | 39 | $app->singleton( 40 | Illuminate\Contracts\Debug\ExceptionHandler::class, 41 | App\Exceptions\Handler::class 42 | ); 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Return The Application 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This script returns the application instance. The instance is given to 50 | | the calling script so we can separate the building of the instances 51 | | from the actual running of the application and sending responses. 52 | | 53 | */ 54 | 55 | return $app; 56 | -------------------------------------------------------------------------------- /bootstrap/autoload.php: -------------------------------------------------------------------------------- 1 | =5.6.4", 9 | "laravel/framework": "5.4.*", 10 | "laravel/tinker": "~1.0", 11 | "spatie/laravel-permission": "^2.1", 12 | "laracasts/flash": "^3.0", 13 | "laravelcollective/html": "^5.3.0" 14 | }, 15 | "require-dev": { 16 | "fzaninotto/faker": "~1.4", 17 | "mockery/mockery": "0.9.*", 18 | "phpunit/phpunit": "~5.7" 19 | }, 20 | "autoload": { 21 | "classmap": [ 22 | "database" 23 | ], 24 | "psr-4": { 25 | "App\\": "app/" 26 | } 27 | }, 28 | "autoload-dev": { 29 | "psr-4": { 30 | "Tests\\": "tests/" 31 | } 32 | }, 33 | "scripts": { 34 | "post-root-package-install": [ 35 | "php -r \"file_exists('.env') || copy('.env.example', '.env');\"" 36 | ], 37 | "post-create-project-cmd": [ 38 | "php artisan key:generate" 39 | ], 40 | "post-install-cmd": [ 41 | "Illuminate\\Foundation\\ComposerScripts::postInstall", 42 | "php artisan optimize" 43 | ], 44 | "post-update-cmd": [ 45 | "Illuminate\\Foundation\\ComposerScripts::postUpdate", 46 | "php artisan optimize" 47 | ] 48 | }, 49 | "config": { 50 | "preferred-install": "dist", 51 | "sort-packages": true, 52 | "optimize-autoloader": true 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /config/app.php: -------------------------------------------------------------------------------- 1 | env('APP_NAME', 'Laravel'), 16 | 17 | /* 18 | |-------------------------------------------------------------------------- 19 | | Application Environment 20 | |-------------------------------------------------------------------------- 21 | | 22 | | This value determines the "environment" your application is currently 23 | | running in. This may determine how you prefer to configure various 24 | | services your application utilizes. Set this in your ".env" file. 25 | | 26 | */ 27 | 28 | 'env' => env('APP_ENV', 'production'), 29 | 30 | /* 31 | |-------------------------------------------------------------------------- 32 | | Application Debug Mode 33 | |-------------------------------------------------------------------------- 34 | | 35 | | When your application is in debug mode, detailed error messages with 36 | | stack traces will be shown on every error that occurs within your 37 | | application. If disabled, a simple generic error page is shown. 38 | | 39 | */ 40 | 41 | 'debug' => env('APP_DEBUG', false), 42 | 43 | /* 44 | |-------------------------------------------------------------------------- 45 | | Application URL 46 | |-------------------------------------------------------------------------- 47 | | 48 | | This URL is used by the console to properly generate URLs when using 49 | | the Artisan command line tool. You should set this to the root of 50 | | your application so that it is used when running Artisan tasks. 51 | | 52 | */ 53 | 54 | 'url' => env('APP_URL', 'http://localhost'), 55 | 56 | /* 57 | |-------------------------------------------------------------------------- 58 | | Application Timezone 59 | |-------------------------------------------------------------------------- 60 | | 61 | | Here you may specify the default timezone for your application, which 62 | | will be used by the PHP date and date-time functions. We have gone 63 | | ahead and set this to a sensible default for you out of the box. 64 | | 65 | */ 66 | 67 | 'timezone' => 'UTC', 68 | 69 | /* 70 | |-------------------------------------------------------------------------- 71 | | Application Locale Configuration 72 | |-------------------------------------------------------------------------- 73 | | 74 | | The application locale determines the default locale that will be used 75 | | by the translation service provider. You are free to set this value 76 | | to any of the locales which will be supported by the application. 77 | | 78 | */ 79 | 80 | 'locale' => 'en', 81 | 82 | /* 83 | |-------------------------------------------------------------------------- 84 | | Application Fallback Locale 85 | |-------------------------------------------------------------------------- 86 | | 87 | | The fallback locale determines the locale to use when the current one 88 | | is not available. You may change the value to correspond to any of 89 | | the language folders that are provided through your application. 90 | | 91 | */ 92 | 93 | 'fallback_locale' => 'en', 94 | 95 | /* 96 | |-------------------------------------------------------------------------- 97 | | Encryption Key 98 | |-------------------------------------------------------------------------- 99 | | 100 | | This key is used by the Illuminate encrypter service and should be set 101 | | to a random, 32 character string, otherwise these encrypted strings 102 | | will not be safe. Please do this before deploying an application! 103 | | 104 | */ 105 | 106 | 'key' => env('APP_KEY'), 107 | 108 | 'cipher' => 'AES-256-CBC', 109 | 110 | /* 111 | |-------------------------------------------------------------------------- 112 | | Logging Configuration 113 | |-------------------------------------------------------------------------- 114 | | 115 | | Here you may configure the log settings for your application. Out of 116 | | the box, Laravel uses the Monolog PHP logging library. This gives 117 | | you a variety of powerful log handlers / formatters to utilize. 118 | | 119 | | Available Settings: "single", "daily", "syslog", "errorlog" 120 | | 121 | */ 122 | 123 | 'log' => env('APP_LOG', 'single'), 124 | 125 | 'log_level' => env('APP_LOG_LEVEL', 'debug'), 126 | 127 | /* 128 | |-------------------------------------------------------------------------- 129 | | Autoloaded Service Providers 130 | |-------------------------------------------------------------------------- 131 | | 132 | | The service providers listed here will be automatically loaded on the 133 | | request to your application. Feel free to add your own services to 134 | | this array to grant expanded functionality to your applications. 135 | | 136 | */ 137 | 138 | 'providers' => [ 139 | 140 | /* 141 | * Laravel Framework Service Providers... 142 | */ 143 | Illuminate\Auth\AuthServiceProvider::class, 144 | Illuminate\Broadcasting\BroadcastServiceProvider::class, 145 | Illuminate\Bus\BusServiceProvider::class, 146 | Illuminate\Cache\CacheServiceProvider::class, 147 | Illuminate\Foundation\Providers\ConsoleSupportServiceProvider::class, 148 | Illuminate\Cookie\CookieServiceProvider::class, 149 | Illuminate\Database\DatabaseServiceProvider::class, 150 | Illuminate\Encryption\EncryptionServiceProvider::class, 151 | Illuminate\Filesystem\FilesystemServiceProvider::class, 152 | Illuminate\Foundation\Providers\FoundationServiceProvider::class, 153 | Illuminate\Hashing\HashServiceProvider::class, 154 | Illuminate\Mail\MailServiceProvider::class, 155 | Illuminate\Notifications\NotificationServiceProvider::class, 156 | Illuminate\Pagination\PaginationServiceProvider::class, 157 | Illuminate\Pipeline\PipelineServiceProvider::class, 158 | Illuminate\Queue\QueueServiceProvider::class, 159 | Illuminate\Redis\RedisServiceProvider::class, 160 | Illuminate\Auth\Passwords\PasswordResetServiceProvider::class, 161 | Illuminate\Session\SessionServiceProvider::class, 162 | Illuminate\Translation\TranslationServiceProvider::class, 163 | Illuminate\Validation\ValidationServiceProvider::class, 164 | Illuminate\View\ViewServiceProvider::class, 165 | 166 | /* 167 | * Package Service Providers... 168 | */ 169 | Laravel\Tinker\TinkerServiceProvider::class, 170 | Spatie\Permission\PermissionServiceProvider::class, 171 | Laracasts\Flash\FlashServiceProvider::class, 172 | Collective\Html\HtmlServiceProvider::class, 173 | 174 | /* 175 | * Application Service Providers... 176 | */ 177 | App\Providers\AppServiceProvider::class, 178 | App\Providers\AuthServiceProvider::class, 179 | // App\Providers\BroadcastServiceProvider::class, 180 | App\Providers\EventServiceProvider::class, 181 | App\Providers\RouteServiceProvider::class, 182 | 183 | ], 184 | 185 | /* 186 | |-------------------------------------------------------------------------- 187 | | Class Aliases 188 | |-------------------------------------------------------------------------- 189 | | 190 | | This array of class aliases will be registered when this application 191 | | is started. However, feel free to register as many as you wish as 192 | | the aliases are "lazy" loaded so they don't hinder performance. 193 | | 194 | */ 195 | 196 | 'aliases' => [ 197 | 198 | 'App' => Illuminate\Support\Facades\App::class, 199 | 'Artisan' => Illuminate\Support\Facades\Artisan::class, 200 | 'Auth' => Illuminate\Support\Facades\Auth::class, 201 | 'Blade' => Illuminate\Support\Facades\Blade::class, 202 | 'Broadcast' => Illuminate\Support\Facades\Broadcast::class, 203 | 'Bus' => Illuminate\Support\Facades\Bus::class, 204 | 'Cache' => Illuminate\Support\Facades\Cache::class, 205 | 'Config' => Illuminate\Support\Facades\Config::class, 206 | 'Cookie' => Illuminate\Support\Facades\Cookie::class, 207 | 'Crypt' => Illuminate\Support\Facades\Crypt::class, 208 | 'DB' => Illuminate\Support\Facades\DB::class, 209 | 'Eloquent' => Illuminate\Database\Eloquent\Model::class, 210 | 'Event' => Illuminate\Support\Facades\Event::class, 211 | 'File' => Illuminate\Support\Facades\File::class, 212 | 'Gate' => Illuminate\Support\Facades\Gate::class, 213 | 'Hash' => Illuminate\Support\Facades\Hash::class, 214 | 'Lang' => Illuminate\Support\Facades\Lang::class, 215 | 'Log' => Illuminate\Support\Facades\Log::class, 216 | 'Mail' => Illuminate\Support\Facades\Mail::class, 217 | 'Notification' => Illuminate\Support\Facades\Notification::class, 218 | 'Password' => Illuminate\Support\Facades\Password::class, 219 | 'Queue' => Illuminate\Support\Facades\Queue::class, 220 | 'Redirect' => Illuminate\Support\Facades\Redirect::class, 221 | 'Redis' => Illuminate\Support\Facades\Redis::class, 222 | 'Request' => Illuminate\Support\Facades\Request::class, 223 | 'Response' => Illuminate\Support\Facades\Response::class, 224 | 'Route' => Illuminate\Support\Facades\Route::class, 225 | 'Schema' => Illuminate\Support\Facades\Schema::class, 226 | 'Session' => Illuminate\Support\Facades\Session::class, 227 | 'Storage' => Illuminate\Support\Facades\Storage::class, 228 | 'URL' => Illuminate\Support\Facades\URL::class, 229 | 'Validator' => Illuminate\Support\Facades\Validator::class, 230 | 'View' => Illuminate\Support\Facades\View::class, 231 | 'Form' => Collective\Html\FormFacade::class, 232 | 'Html' => Collective\Html\HtmlFacade::class, 233 | 234 | ], 235 | 236 | ]; 237 | -------------------------------------------------------------------------------- /config/auth.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'guard' => 'web', 18 | 'passwords' => 'users', 19 | ], 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Authentication Guards 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Next, you may define every authentication guard for your application. 27 | | Of course, a great default configuration has been defined for you 28 | | here which uses session storage and the Eloquent user provider. 29 | | 30 | | All authentication drivers have a user provider. This defines how the 31 | | users are actually retrieved out of your database or other storage 32 | | mechanisms used by this application to persist your user's data. 33 | | 34 | | Supported: "session", "token" 35 | | 36 | */ 37 | 38 | 'guards' => [ 39 | 'web' => [ 40 | 'driver' => 'session', 41 | 'provider' => 'users', 42 | ], 43 | 44 | 'api' => [ 45 | 'driver' => 'token', 46 | 'provider' => 'users', 47 | ], 48 | ], 49 | 50 | /* 51 | |-------------------------------------------------------------------------- 52 | | User Providers 53 | |-------------------------------------------------------------------------- 54 | | 55 | | All authentication drivers have a user provider. This defines how the 56 | | users are actually retrieved out of your database or other storage 57 | | mechanisms used by this application to persist your user's data. 58 | | 59 | | If you have multiple user tables or models you may configure multiple 60 | | sources which represent each model / table. These sources may then 61 | | be assigned to any extra authentication guards you have defined. 62 | | 63 | | Supported: "database", "eloquent" 64 | | 65 | */ 66 | 67 | 'providers' => [ 68 | 'users' => [ 69 | 'driver' => 'eloquent', 70 | 'model' => App\User::class, 71 | ], 72 | 73 | // 'users' => [ 74 | // 'driver' => 'database', 75 | // 'table' => 'users', 76 | // ], 77 | ], 78 | 79 | /* 80 | |-------------------------------------------------------------------------- 81 | | Resetting Passwords 82 | |-------------------------------------------------------------------------- 83 | | 84 | | You may specify multiple password reset configurations if you have more 85 | | than one user table or model in the application and you want to have 86 | | separate password reset settings based on the specific user types. 87 | | 88 | | The expire time is the number of minutes that the reset token should be 89 | | considered valid. This security feature keeps tokens short-lived so 90 | | they have less time to be guessed. You may change this as needed. 91 | | 92 | */ 93 | 94 | 'passwords' => [ 95 | 'users' => [ 96 | 'provider' => 'users', 97 | 'table' => 'password_resets', 98 | 'expire' => 60, 99 | ], 100 | ], 101 | 102 | ]; 103 | -------------------------------------------------------------------------------- /config/broadcasting.php: -------------------------------------------------------------------------------- 1 | env('BROADCAST_DRIVER', 'null'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Broadcast Connections 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the broadcast connections that will be used 26 | | to broadcast events to other systems or over websockets. Samples of 27 | | each available type of connection are provided inside this array. 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'pusher' => [ 34 | 'driver' => 'pusher', 35 | 'key' => env('PUSHER_APP_KEY'), 36 | 'secret' => env('PUSHER_APP_SECRET'), 37 | 'app_id' => env('PUSHER_APP_ID'), 38 | 'options' => [ 39 | // 40 | ], 41 | ], 42 | 43 | 'redis' => [ 44 | 'driver' => 'redis', 45 | 'connection' => 'default', 46 | ], 47 | 48 | 'log' => [ 49 | 'driver' => 'log', 50 | ], 51 | 52 | 'null' => [ 53 | 'driver' => 'null', 54 | ], 55 | 56 | ], 57 | 58 | ]; 59 | -------------------------------------------------------------------------------- /config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_DRIVER', 'file'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Cache Stores 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the cache "stores" for your application as 26 | | well as their drivers. You may even define multiple stores for the 27 | | same cache driver to group types of items stored in your caches. 28 | | 29 | */ 30 | 31 | 'stores' => [ 32 | 33 | 'apc' => [ 34 | 'driver' => 'apc', 35 | ], 36 | 37 | 'array' => [ 38 | 'driver' => 'array', 39 | ], 40 | 41 | 'database' => [ 42 | 'driver' => 'database', 43 | 'table' => 'cache', 44 | 'connection' => null, 45 | ], 46 | 47 | 'file' => [ 48 | 'driver' => 'file', 49 | 'path' => storage_path('framework/cache/data'), 50 | ], 51 | 52 | 'memcached' => [ 53 | 'driver' => 'memcached', 54 | 'persistent_id' => env('MEMCACHED_PERSISTENT_ID'), 55 | 'sasl' => [ 56 | env('MEMCACHED_USERNAME'), 57 | env('MEMCACHED_PASSWORD'), 58 | ], 59 | 'options' => [ 60 | // Memcached::OPT_CONNECT_TIMEOUT => 2000, 61 | ], 62 | 'servers' => [ 63 | [ 64 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 65 | 'port' => env('MEMCACHED_PORT', 11211), 66 | 'weight' => 100, 67 | ], 68 | ], 69 | ], 70 | 71 | 'redis' => [ 72 | 'driver' => 'redis', 73 | 'connection' => 'default', 74 | ], 75 | 76 | ], 77 | 78 | /* 79 | |-------------------------------------------------------------------------- 80 | | Cache Key Prefix 81 | |-------------------------------------------------------------------------- 82 | | 83 | | When utilizing a RAM based store such as APC or Memcached, there might 84 | | be other applications utilizing the same cache. So, we'll specify a 85 | | value to get prefixed to all our keys so we can avoid collisions. 86 | | 87 | */ 88 | 89 | 'prefix' => 'laravel', 90 | 91 | ]; 92 | -------------------------------------------------------------------------------- /config/database.php: -------------------------------------------------------------------------------- 1 | env('DB_CONNECTION', 'mysql'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Database Connections 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Here are each of the database connections setup for your application. 24 | | Of course, examples of configuring each database platform that is 25 | | supported by Laravel is shown below to make development simple. 26 | | 27 | | 28 | | All database work in Laravel is done through the PHP PDO facilities 29 | | so make sure you have the driver for your particular database of 30 | | choice installed on your machine before you begin development. 31 | | 32 | */ 33 | 34 | 'connections' => [ 35 | 36 | 'sqlite' => [ 37 | 'driver' => 'sqlite', 38 | 'database' => env('DB_DATABASE', database_path('database.sqlite')), 39 | 'prefix' => '', 40 | ], 41 | 42 | 'mysql' => [ 43 | 'driver' => 'mysql', 44 | 'host' => env('DB_HOST', '127.0.0.1'), 45 | 'port' => env('DB_PORT', '3306'), 46 | 'database' => env('DB_DATABASE', 'forge'), 47 | 'username' => env('DB_USERNAME', 'forge'), 48 | 'password' => env('DB_PASSWORD', ''), 49 | 'unix_socket' => env('DB_SOCKET', ''), 50 | 'charset' => 'utf8mb4', 51 | 'collation' => 'utf8mb4_unicode_ci', 52 | 'prefix' => '', 53 | 'strict' => true, 54 | 'engine' => null, 55 | ], 56 | 57 | 'pgsql' => [ 58 | 'driver' => 'pgsql', 59 | 'host' => env('DB_HOST', '127.0.0.1'), 60 | 'port' => env('DB_PORT', '5432'), 61 | 'database' => env('DB_DATABASE', 'forge'), 62 | 'username' => env('DB_USERNAME', 'forge'), 63 | 'password' => env('DB_PASSWORD', ''), 64 | 'charset' => 'utf8', 65 | 'prefix' => '', 66 | 'schema' => 'public', 67 | 'sslmode' => 'prefer', 68 | ], 69 | 70 | ], 71 | 72 | /* 73 | |-------------------------------------------------------------------------- 74 | | Migration Repository Table 75 | |-------------------------------------------------------------------------- 76 | | 77 | | This table keeps track of all the migrations that have already run for 78 | | your application. Using this information, we can determine which of 79 | | the migrations on disk haven't actually been run in the database. 80 | | 81 | */ 82 | 83 | 'migrations' => 'migrations', 84 | 85 | /* 86 | |-------------------------------------------------------------------------- 87 | | Redis Databases 88 | |-------------------------------------------------------------------------- 89 | | 90 | | Redis is an open source, fast, and advanced key-value store that also 91 | | provides a richer set of commands than a typical key-value systems 92 | | such as APC or Memcached. Laravel makes it easy to dig right in. 93 | | 94 | */ 95 | 96 | 'redis' => [ 97 | 98 | 'client' => 'predis', 99 | 100 | 'default' => [ 101 | 'host' => env('REDIS_HOST', '127.0.0.1'), 102 | 'password' => env('REDIS_PASSWORD', null), 103 | 'port' => env('REDIS_PORT', 6379), 104 | 'database' => 0, 105 | ], 106 | 107 | ], 108 | 109 | ]; 110 | -------------------------------------------------------------------------------- /config/filesystems.php: -------------------------------------------------------------------------------- 1 | env('FILESYSTEM_DRIVER', 'local'), 17 | 18 | /* 19 | |-------------------------------------------------------------------------- 20 | | Default Cloud Filesystem Disk 21 | |-------------------------------------------------------------------------- 22 | | 23 | | Many applications store files both locally and in the cloud. For this 24 | | reason, you may specify a default "cloud" driver here. This driver 25 | | will be bound as the Cloud disk implementation in the container. 26 | | 27 | */ 28 | 29 | 'cloud' => env('FILESYSTEM_CLOUD', 's3'), 30 | 31 | /* 32 | |-------------------------------------------------------------------------- 33 | | Filesystem Disks 34 | |-------------------------------------------------------------------------- 35 | | 36 | | Here you may configure as many filesystem "disks" as you wish, and you 37 | | may even configure multiple disks of the same driver. Defaults have 38 | | been setup for each driver as an example of the required options. 39 | | 40 | | Supported Drivers: "local", "ftp", "s3", "rackspace" 41 | | 42 | */ 43 | 44 | 'disks' => [ 45 | 46 | 'local' => [ 47 | 'driver' => 'local', 48 | 'root' => storage_path('app'), 49 | ], 50 | 51 | 'public' => [ 52 | 'driver' => 'local', 53 | 'root' => storage_path('app/public'), 54 | 'url' => env('APP_URL').'/storage', 55 | 'visibility' => 'public', 56 | ], 57 | 58 | 's3' => [ 59 | 'driver' => 's3', 60 | 'key' => env('AWS_KEY'), 61 | 'secret' => env('AWS_SECRET'), 62 | 'region' => env('AWS_REGION'), 63 | 'bucket' => env('AWS_BUCKET'), 64 | ], 65 | 66 | ], 67 | 68 | ]; 69 | -------------------------------------------------------------------------------- /config/mail.php: -------------------------------------------------------------------------------- 1 | env('MAIL_DRIVER', 'smtp'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | SMTP Host Address 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may provide the host address of the SMTP server used by your 27 | | applications. A default option is provided that is compatible with 28 | | the Mailgun mail service which will provide reliable deliveries. 29 | | 30 | */ 31 | 32 | 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 33 | 34 | /* 35 | |-------------------------------------------------------------------------- 36 | | SMTP Host Port 37 | |-------------------------------------------------------------------------- 38 | | 39 | | This is the SMTP port used by your application to deliver e-mails to 40 | | users of the application. Like the host we have set this value to 41 | | stay compatible with the Mailgun e-mail application by default. 42 | | 43 | */ 44 | 45 | 'port' => env('MAIL_PORT', 587), 46 | 47 | /* 48 | |-------------------------------------------------------------------------- 49 | | Global "From" Address 50 | |-------------------------------------------------------------------------- 51 | | 52 | | You may wish for all e-mails sent by your application to be sent from 53 | | the same address. Here, you may specify a name and address that is 54 | | used globally for all e-mails that are sent by your application. 55 | | 56 | */ 57 | 58 | 'from' => [ 59 | 'address' => env('MAIL_FROM_ADDRESS', 'hello@example.com'), 60 | 'name' => env('MAIL_FROM_NAME', 'Example'), 61 | ], 62 | 63 | /* 64 | |-------------------------------------------------------------------------- 65 | | E-Mail Encryption Protocol 66 | |-------------------------------------------------------------------------- 67 | | 68 | | Here you may specify the encryption protocol that should be used when 69 | | the application send e-mail messages. A sensible default using the 70 | | transport layer security protocol should provide great security. 71 | | 72 | */ 73 | 74 | 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 75 | 76 | /* 77 | |-------------------------------------------------------------------------- 78 | | SMTP Server Username 79 | |-------------------------------------------------------------------------- 80 | | 81 | | If your SMTP server requires a username for authentication, you should 82 | | set it here. This will get used to authenticate with your server on 83 | | connection. You may also set the "password" value below this one. 84 | | 85 | */ 86 | 87 | 'username' => env('MAIL_USERNAME'), 88 | 89 | 'password' => env('MAIL_PASSWORD'), 90 | 91 | /* 92 | |-------------------------------------------------------------------------- 93 | | Sendmail System Path 94 | |-------------------------------------------------------------------------- 95 | | 96 | | When using the "sendmail" driver to send e-mails, we will need to know 97 | | the path to where Sendmail lives on this server. A default path has 98 | | been provided here, which will work well on most of your systems. 99 | | 100 | */ 101 | 102 | 'sendmail' => '/usr/sbin/sendmail -bs', 103 | 104 | /* 105 | |-------------------------------------------------------------------------- 106 | | Markdown Mail Settings 107 | |-------------------------------------------------------------------------- 108 | | 109 | | If you are using Markdown based email rendering, you may configure your 110 | | theme and component paths here, allowing you to customize the design 111 | | of the emails. Or, you may simply stick with the Laravel defaults! 112 | | 113 | */ 114 | 115 | 'markdown' => [ 116 | 'theme' => 'default', 117 | 118 | 'paths' => [ 119 | resource_path('views/vendor/mail'), 120 | ], 121 | ], 122 | 123 | ]; 124 | -------------------------------------------------------------------------------- /config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_DRIVER', 'sync'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Queue Connections 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may configure the connection information for each server that 26 | | is used by your application. A default configuration has been added 27 | | for each back-end shipped with Laravel. You are free to add more. 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'sync' => [ 34 | 'driver' => 'sync', 35 | ], 36 | 37 | 'database' => [ 38 | 'driver' => 'database', 39 | 'table' => 'jobs', 40 | 'queue' => 'default', 41 | 'retry_after' => 90, 42 | ], 43 | 44 | 'beanstalkd' => [ 45 | 'driver' => 'beanstalkd', 46 | 'host' => 'localhost', 47 | 'queue' => 'default', 48 | 'retry_after' => 90, 49 | ], 50 | 51 | 'sqs' => [ 52 | 'driver' => 'sqs', 53 | 'key' => 'your-public-key', 54 | 'secret' => 'your-secret-key', 55 | 'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-account-id', 56 | 'queue' => 'your-queue-name', 57 | 'region' => 'us-east-1', 58 | ], 59 | 60 | 'redis' => [ 61 | 'driver' => 'redis', 62 | 'connection' => 'default', 63 | 'queue' => 'default', 64 | 'retry_after' => 90, 65 | ], 66 | 67 | ], 68 | 69 | /* 70 | |-------------------------------------------------------------------------- 71 | | Failed Queue Jobs 72 | |-------------------------------------------------------------------------- 73 | | 74 | | These options configure the behavior of failed queue job logging so you 75 | | can control which database and table are used to store the jobs that 76 | | have failed. You may change them to any database / table you wish. 77 | | 78 | */ 79 | 80 | 'failed' => [ 81 | 'database' => env('DB_CONNECTION', 'mysql'), 82 | 'table' => 'failed_jobs', 83 | ], 84 | 85 | ]; 86 | -------------------------------------------------------------------------------- /config/services.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'domain' => env('MAILGUN_DOMAIN'), 19 | 'secret' => env('MAILGUN_SECRET'), 20 | ], 21 | 22 | 'ses' => [ 23 | 'key' => env('SES_KEY'), 24 | 'secret' => env('SES_SECRET'), 25 | 'region' => 'us-east-1', 26 | ], 27 | 28 | 'sparkpost' => [ 29 | 'secret' => env('SPARKPOST_SECRET'), 30 | ], 31 | 32 | 'stripe' => [ 33 | 'model' => App\User::class, 34 | 'key' => env('STRIPE_KEY'), 35 | 'secret' => env('STRIPE_SECRET'), 36 | ], 37 | 38 | ]; 39 | -------------------------------------------------------------------------------- /config/session.php: -------------------------------------------------------------------------------- 1 | env('SESSION_DRIVER', 'file'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Session Lifetime 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may specify the number of minutes that you wish the session 27 | | to be allowed to remain idle before it expires. If you want them 28 | | to immediately expire on the browser closing, set that option. 29 | | 30 | */ 31 | 32 | 'lifetime' => 120, 33 | 34 | 'expire_on_close' => false, 35 | 36 | /* 37 | |-------------------------------------------------------------------------- 38 | | Session Encryption 39 | |-------------------------------------------------------------------------- 40 | | 41 | | This option allows you to easily specify that all of your session data 42 | | should be encrypted before it is stored. All encryption will be run 43 | | automatically by Laravel and you can use the Session like normal. 44 | | 45 | */ 46 | 47 | 'encrypt' => false, 48 | 49 | /* 50 | |-------------------------------------------------------------------------- 51 | | Session File Location 52 | |-------------------------------------------------------------------------- 53 | | 54 | | When using the native session driver, we need a location where session 55 | | files may be stored. A default has been set for you but a different 56 | | location may be specified. This is only needed for file sessions. 57 | | 58 | */ 59 | 60 | 'files' => storage_path('framework/sessions'), 61 | 62 | /* 63 | |-------------------------------------------------------------------------- 64 | | Session Database Connection 65 | |-------------------------------------------------------------------------- 66 | | 67 | | When using the "database" or "redis" session drivers, you may specify a 68 | | connection that should be used to manage these sessions. This should 69 | | correspond to a connection in your database configuration options. 70 | | 71 | */ 72 | 73 | 'connection' => null, 74 | 75 | /* 76 | |-------------------------------------------------------------------------- 77 | | Session Database Table 78 | |-------------------------------------------------------------------------- 79 | | 80 | | When using the "database" session driver, you may specify the table we 81 | | should use to manage the sessions. Of course, a sensible default is 82 | | provided for you; however, you are free to change this as needed. 83 | | 84 | */ 85 | 86 | 'table' => 'sessions', 87 | 88 | /* 89 | |-------------------------------------------------------------------------- 90 | | Session Cache Store 91 | |-------------------------------------------------------------------------- 92 | | 93 | | When using the "apc" or "memcached" session drivers, you may specify a 94 | | cache store that should be used for these sessions. This value must 95 | | correspond with one of the application's configured cache stores. 96 | | 97 | */ 98 | 99 | 'store' => null, 100 | 101 | /* 102 | |-------------------------------------------------------------------------- 103 | | Session Sweeping Lottery 104 | |-------------------------------------------------------------------------- 105 | | 106 | | Some session drivers must manually sweep their storage location to get 107 | | rid of old sessions from storage. Here are the chances that it will 108 | | happen on a given request. By default, the odds are 2 out of 100. 109 | | 110 | */ 111 | 112 | 'lottery' => [2, 100], 113 | 114 | /* 115 | |-------------------------------------------------------------------------- 116 | | Session Cookie Name 117 | |-------------------------------------------------------------------------- 118 | | 119 | | Here you may change the name of the cookie used to identify a session 120 | | instance by ID. The name specified here will get used every time a 121 | | new session cookie is created by the framework for every driver. 122 | | 123 | */ 124 | 125 | 'cookie' => 'laravel_session', 126 | 127 | /* 128 | |-------------------------------------------------------------------------- 129 | | Session Cookie Path 130 | |-------------------------------------------------------------------------- 131 | | 132 | | The session cookie path determines the path for which the cookie will 133 | | be regarded as available. Typically, this will be the root path of 134 | | your application but you are free to change this when necessary. 135 | | 136 | */ 137 | 138 | 'path' => '/', 139 | 140 | /* 141 | |-------------------------------------------------------------------------- 142 | | Session Cookie Domain 143 | |-------------------------------------------------------------------------- 144 | | 145 | | Here you may change the domain of the cookie used to identify a session 146 | | in your application. This will determine which domains the cookie is 147 | | available to in your application. A sensible default has been set. 148 | | 149 | */ 150 | 151 | 'domain' => env('SESSION_DOMAIN', null), 152 | 153 | /* 154 | |-------------------------------------------------------------------------- 155 | | HTTPS Only Cookies 156 | |-------------------------------------------------------------------------- 157 | | 158 | | By setting this option to true, session cookies will only be sent back 159 | | to the server if the browser has a HTTPS connection. This will keep 160 | | the cookie from being sent to you if it can not be done securely. 161 | | 162 | */ 163 | 164 | 'secure' => env('SESSION_SECURE_COOKIE', false), 165 | 166 | /* 167 | |-------------------------------------------------------------------------- 168 | | HTTP Access Only 169 | |-------------------------------------------------------------------------- 170 | | 171 | | Setting this value to true will prevent JavaScript from accessing the 172 | | value of the cookie and the cookie will only be accessible through 173 | | the HTTP protocol. You are free to modify this option if needed. 174 | | 175 | */ 176 | 177 | 'http_only' => true, 178 | 179 | ]; 180 | -------------------------------------------------------------------------------- /config/view.php: -------------------------------------------------------------------------------- 1 | [ 17 | resource_path('views'), 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled View Path 23 | |-------------------------------------------------------------------------- 24 | | 25 | | This option determines where all the compiled Blade templates will be 26 | | stored for your application. Typically, this is within the storage 27 | | directory. However, as usual, you are free to change this value. 28 | | 29 | */ 30 | 31 | 'compiled' => realpath(storage_path('framework/views')), 32 | 33 | ]; 34 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite 2 | -------------------------------------------------------------------------------- /database/factories/ModelFactory.php: -------------------------------------------------------------------------------- 1 | define(App\User::class, function (Faker\Generator $faker) { 16 | static $password; 17 | 18 | return [ 19 | 'name' => $faker->name, 20 | 'email' => $faker->unique()->safeEmail, 21 | 'password' => $password ?: $password = bcrypt('secret'), 22 | 'remember_token' => str_random(10), 23 | ]; 24 | }); 25 | 26 | $factory->define(App\Post::class, function(Faker\Generator $faker) { 27 | return [ 28 | 'title' => $faker->realText(rand(40, 80)), 29 | 'body' => $faker->realText(rand(200, 6000)), 30 | 'user_id' => function() { 31 | return \App\User::inRandomOrder()->first()->id; 32 | } 33 | ]; 34 | }); 35 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->string('name'); 19 | $table->string('email')->unique(); 20 | $table->string('password'); 21 | $table->rememberToken(); 22 | $table->timestamps(); 23 | }); 24 | } 25 | 26 | /** 27 | * Reverse the migrations. 28 | * 29 | * @return void 30 | */ 31 | public function down() 32 | { 33 | Schema::dropIfExists('users'); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /database/migrations/2014_10_12_100000_create_password_resets_table.php: -------------------------------------------------------------------------------- 1 | string('email')->index(); 18 | $table->string('token'); 19 | $table->timestamp('created_at')->nullable(); 20 | }); 21 | } 22 | 23 | /** 24 | * Reverse the migrations. 25 | * 26 | * @return void 27 | */ 28 | public function down() 29 | { 30 | Schema::dropIfExists('password_resets'); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /database/migrations/2017_04_30_012311_create_posts_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 18 | $table->string('title'); 19 | $table->text('body'); 20 | $table->unsignedInteger('user_id'); 21 | 22 | $table->foreign('user_id') 23 | ->references('id')->on('users') 24 | ->onDelete('cascade'); 25 | 26 | $table->timestamps(); 27 | }); 28 | } 29 | 30 | /** 31 | * Reverse the migrations. 32 | * 33 | * @return void 34 | */ 35 | public function down() 36 | { 37 | Schema::dropIfExists('posts'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /database/migrations/2017_04_30_014352_create_permission_tables.php: -------------------------------------------------------------------------------- 1 | increments('id'); 20 | $table->string('name'); 21 | $table->string('guard_name'); 22 | $table->timestamps(); 23 | }); 24 | 25 | Schema::create($tableNames['roles'], function (Blueprint $table) { 26 | $table->increments('id'); 27 | $table->string('name'); 28 | $table->string('guard_name'); 29 | $table->timestamps(); 30 | }); 31 | 32 | Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $foreignKeys) { 33 | $table->integer('permission_id')->unsigned(); 34 | $table->morphs('model'); 35 | 36 | $table->foreign('permission_id') 37 | ->references('id') 38 | ->on($tableNames['permissions']) 39 | ->onDelete('cascade'); 40 | 41 | $table->primary(['permission_id', 'model_id']); 42 | }); 43 | 44 | Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $foreignKeys) { 45 | $table->integer('role_id')->unsigned(); 46 | $table->morphs('model'); 47 | 48 | $table->foreign('role_id') 49 | ->references('id') 50 | ->on($tableNames['roles']) 51 | ->onDelete('cascade'); 52 | 53 | $table->primary(['role_id', 'model_id']); 54 | }); 55 | 56 | Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) { 57 | $table->integer('permission_id')->unsigned(); 58 | $table->integer('role_id')->unsigned(); 59 | 60 | $table->foreign('permission_id') 61 | ->references('id') 62 | ->on($tableNames['permissions']) 63 | ->onDelete('cascade'); 64 | 65 | $table->foreign('role_id') 66 | ->references('id') 67 | ->on($tableNames['roles']) 68 | ->onDelete('cascade'); 69 | 70 | $table->primary(['permission_id', 'role_id']); 71 | }); 72 | } 73 | 74 | /** 75 | * Reverse the migrations. 76 | * 77 | * @return void 78 | */ 79 | public function down() 80 | { 81 | $tableNames = config('permission.table_names'); 82 | 83 | Schema::drop($tableNames['role_has_permissions']); 84 | Schema::drop($tableNames['model_has_roles']); 85 | Schema::drop($tableNames['model_has_permissions']); 86 | Schema::drop($tableNames['roles']); 87 | Schema::drop($tableNames['permissions']); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /database/seeds/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | command->confirm('Do you wish to refresh migration before seeding, it will clear all old data ?')) { 19 | // disable fk constrain check 20 | // \DB::statement('SET FOREIGN_KEY_CHECKS=0;'); 21 | 22 | // Call the php artisan migrate:refresh 23 | $this->command->call('migrate:refresh'); 24 | $this->command->warn("Data cleared, starting from blank database."); 25 | 26 | // enable back fk constrain check 27 | // \DB::statement('SET FOREIGN_KEY_CHECKS=1;'); 28 | } 29 | 30 | 31 | // Seed the default permissions 32 | $permissions = Permission::defaultPermissions(); 33 | 34 | foreach ($permissions as $perms) { 35 | Permission::firstOrCreate(['name' => $perms]); 36 | } 37 | 38 | $this->command->info('Default Permissions added.'); 39 | 40 | // Confirm roles needed 41 | if ($this->command->confirm('Create Roles for user, default is admin and user? [y|N]', true)) { 42 | 43 | // Ask for roles from input 44 | $input_roles = $this->command->ask('Enter roles in comma separate format.', 'Admin,User'); 45 | 46 | // Explode roles 47 | $roles_array = explode(',', $input_roles); 48 | 49 | // add roles 50 | foreach($roles_array as $role) { 51 | $role = Role::firstOrCreate(['name' => trim($role)]); 52 | 53 | if( $role->name == 'Admin' ) { 54 | // assign all permissions 55 | $role->syncPermissions(Permission::all()); 56 | $this->command->info('Admin granted all the permissions'); 57 | } else { 58 | // for others by default only read access 59 | $role->syncPermissions(Permission::where('name', 'LIKE', 'view_%')->get()); 60 | } 61 | 62 | // create one user for each role 63 | $this->createUser($role); 64 | } 65 | 66 | $this->command->info('Roles ' . $input_roles . ' added successfully'); 67 | 68 | } else { 69 | Role::firstOrCreate(['name' => 'User']); 70 | $this->command->info('Added only default user role.'); 71 | } 72 | 73 | 74 | // now lets seed some posts for demo 75 | factory(\App\Post::class, 30)->create(); 76 | $this->command->info('Some Posts data seeded.'); 77 | $this->command->warn('All done :)'); 78 | } 79 | 80 | /** 81 | * Create a user with given role 82 | * 83 | * @param $role 84 | */ 85 | private function createUser($role) 86 | { 87 | $user = factory(User::class)->create(); 88 | $user->assignRole($role->name); 89 | 90 | if( $role->name == 'Admin' ) { 91 | $this->command->info('Here is your admin details to login:'); 92 | $this->command->warn($user->email); 93 | $this->command->warn('Password is "secret"'); 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "dev": "npm run development", 5 | "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", 6 | "watch": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --watch --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js", 7 | "watch-poll": "npm run watch -- --watch-poll", 8 | "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js", 9 | "prod": "npm run production", 10 | "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" 11 | }, 12 | "devDependencies": { 13 | "axios": "^0.15.3", 14 | "bootstrap-sass": "^3.3.7", 15 | "cross-env": "^3.2.3", 16 | "jquery": "^3.1.1", 17 | "laravel-mix": "0.*", 18 | "lodash": "^4.17.4", 19 | "vue": "^2.1.10" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | ./tests/Feature 14 | 15 | 16 | 17 | ./tests/Unit 18 | 19 | 20 | 21 | 22 | ./app 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Redirect Trailing Slashes If Not A Folder... 9 | RewriteCond %{REQUEST_FILENAME} !-d 10 | RewriteRule ^(.*)/$ /$1 [L,R=301] 11 | 12 | # Handle Front Controller... 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | RewriteCond %{REQUEST_FILENAME} !-f 15 | RewriteRule ^ index.php [L] 16 | 17 | # Handle Authorization Header 18 | RewriteCond %{HTTP:Authorization} . 19 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 20 | 21 | -------------------------------------------------------------------------------- /public/css/fonts/glyphicons-halflings-regular.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saqueib/roles-permissions-laravel/9f19ce57c726af1a1d82447bab7f18c54684a8d6/public/css/fonts/glyphicons-halflings-regular.eot -------------------------------------------------------------------------------- /public/css/fonts/glyphicons-halflings-regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saqueib/roles-permissions-laravel/9f19ce57c726af1a1d82447bab7f18c54684a8d6/public/css/fonts/glyphicons-halflings-regular.ttf -------------------------------------------------------------------------------- /public/css/fonts/glyphicons-halflings-regular.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saqueib/roles-permissions-laravel/9f19ce57c726af1a1d82447bab7f18c54684a8d6/public/css/fonts/glyphicons-halflings-regular.woff -------------------------------------------------------------------------------- /public/css/fonts/glyphicons-halflings-regular.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saqueib/roles-permissions-laravel/9f19ce57c726af1a1d82447bab7f18c54684a8d6/public/css/fonts/glyphicons-halflings-regular.woff2 -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saqueib/roles-permissions-laravel/9f19ce57c726af1a1d82447bab7f18c54684a8d6/public/favicon.ico -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | /* 11 | |-------------------------------------------------------------------------- 12 | | Register The Auto Loader 13 | |-------------------------------------------------------------------------- 14 | | 15 | | Composer provides a convenient, automatically generated class loader for 16 | | our application. We just need to utilize it! We'll simply require it 17 | | into the script here so that we don't have to worry about manual 18 | | loading any of our classes later on. It feels great to relax. 19 | | 20 | */ 21 | 22 | require __DIR__.'/../bootstrap/autoload.php'; 23 | 24 | /* 25 | |-------------------------------------------------------------------------- 26 | | Turn On The Lights 27 | |-------------------------------------------------------------------------- 28 | | 29 | | We need to illuminate PHP development, so let us turn on the lights. 30 | | This bootstraps the framework and gets it ready for use, then it 31 | | will load up this application so that we can run it and send 32 | | the responses back to the browser and delight our users. 33 | | 34 | */ 35 | 36 | $app = require_once __DIR__.'/../bootstrap/app.php'; 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Run The Application 41 | |-------------------------------------------------------------------------- 42 | | 43 | | Once we have the application, we can handle the incoming request 44 | | through the kernel, and send the associated response back to 45 | | the client's browser allowing them to enjoy the creative 46 | | and wonderful application we have prepared for them. 47 | | 48 | */ 49 | 50 | $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); 51 | 52 | $response = $kernel->handle( 53 | $request = Illuminate\Http\Request::capture() 54 | ); 55 | 56 | $response->send(); 57 | 58 | $kernel->terminate($request, $response); 59 | -------------------------------------------------------------------------------- /public/js/particlesjs-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "particles": { 3 | "number": { 4 | "value": 80, 5 | "density": { 6 | "enable": true, 7 | "value_area": 800 8 | } 9 | }, 10 | "color": { 11 | "value": "#f4645f" 12 | }, 13 | "shape": { 14 | "type": "circle", 15 | "stroke": { 16 | "width": 0, 17 | "color": "#000000" 18 | }, 19 | "polygon": { 20 | "nb_sides": 5 21 | }, 22 | "image": { 23 | "src": "img/github.svg", 24 | "width": 100, 25 | "height": 100 26 | } 27 | }, 28 | "opacity": { 29 | "value": 0.5, 30 | "random": false, 31 | "anim": { 32 | "enable": false, 33 | "speed": 1, 34 | "opacity_min": 0.1, 35 | "sync": false 36 | } 37 | }, 38 | "size": { 39 | "value": 3, 40 | "random": true, 41 | "anim": { 42 | "enable": false, 43 | "speed": 40, 44 | "size_min": 0.1, 45 | "sync": false 46 | } 47 | }, 48 | "line_linked": { 49 | "enable": true, 50 | "distance": 150, 51 | "color": "#f4645f", 52 | "opacity": 0.4, 53 | "width": 1 54 | }, 55 | "move": { 56 | "enable": true, 57 | "speed": 6, 58 | "direction": "none", 59 | "random": false, 60 | "straight": false, 61 | "out_mode": "out", 62 | "bounce": false, 63 | "attract": { 64 | "enable": false, 65 | "rotateX": 600, 66 | "rotateY": 1200 67 | } 68 | } 69 | }, 70 | "interactivity": { 71 | "detect_on": "window", 72 | "events": { 73 | "onhover": { 74 | "enable": true, 75 | "mode": "repulse" 76 | }, 77 | "onclick": { 78 | "enable": true, 79 | "mode": "push" 80 | }, 81 | "resize": true 82 | }, 83 | "modes": { 84 | "grab": { 85 | "distance": 400, 86 | "line_linked": { 87 | "opacity": 1 88 | } 89 | }, 90 | "bubble": { 91 | "distance": 400, 92 | "size": 40, 93 | "duration": 2, 94 | "opacity": 8, 95 | "speed": 3 96 | }, 97 | "repulse": { 98 | "distance": 200, 99 | "duration": 0.4 100 | }, 101 | "push": { 102 | "particles_nb": 4 103 | }, 104 | "remove": { 105 | "particles_nb": 2 106 | } 107 | } 108 | }, 109 | "retina_detect": true 110 | } -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /resources/assets/js/app.js: -------------------------------------------------------------------------------- 1 | 2 | /** 3 | * First we will load all of this project's JavaScript dependencies which 4 | * includes Vue and other libraries. It is a great starting point when 5 | * building robust, powerful web applications using Vue and Laravel. 6 | */ 7 | 8 | require('./bootstrap'); 9 | 10 | window.Vue = require('vue'); 11 | 12 | /** 13 | * Next, we will create a fresh Vue application instance and attach it to 14 | * the page. Then, you may begin adding components to this application 15 | * or customize the JavaScript scaffolding to fit your unique needs. 16 | */ 17 | 18 | Vue.component('example', require('./components/Example.vue')); 19 | 20 | const app = new Vue({ 21 | el: '#app' 22 | }); 23 | -------------------------------------------------------------------------------- /resources/assets/js/bootstrap.js: -------------------------------------------------------------------------------- 1 | 2 | window._ = require('lodash'); 3 | 4 | /** 5 | * We'll load jQuery and the Bootstrap jQuery plugin which provides support 6 | * for JavaScript based Bootstrap features such as modals and tabs. This 7 | * code may be modified to fit the specific needs of your application. 8 | */ 9 | 10 | try { 11 | window.$ = window.jQuery = require('jquery'); 12 | 13 | require('bootstrap-sass'); 14 | } catch (e) {} 15 | 16 | /** 17 | * We'll load the axios HTTP library which allows us to easily issue requests 18 | * to our Laravel back-end. This library automatically handles sending the 19 | * CSRF token as a header based on the value of the "XSRF" token cookie. 20 | */ 21 | 22 | window.axios = require('axios'); 23 | 24 | window.axios.defaults.headers.common['X-CSRF-TOKEN'] = window.Laravel.csrfToken; 25 | window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 26 | 27 | /** 28 | * Echo exposes an expressive API for subscribing to channels and listening 29 | * for events that are broadcast by Laravel. Echo and event broadcasting 30 | * allows your team to easily build robust real-time web applications. 31 | */ 32 | 33 | // import Echo from 'laravel-echo' 34 | 35 | // window.Pusher = require('pusher-js'); 36 | 37 | // window.Echo = new Echo({ 38 | // broadcaster: 'pusher', 39 | // key: 'your-pusher-key' 40 | // }); 41 | -------------------------------------------------------------------------------- /resources/assets/js/components/Example.vue: -------------------------------------------------------------------------------- 1 | 16 | 17 | 24 | -------------------------------------------------------------------------------- /resources/assets/sass/_variables.scss: -------------------------------------------------------------------------------- 1 | 2 | // Body 3 | $body-bg: #f5f8fa; 4 | 5 | // Borders 6 | $laravel-border-color: darken($body-bg, 10%); 7 | $list-group-border: $laravel-border-color; 8 | $navbar-default-border: $laravel-border-color; 9 | $panel-default-border: $laravel-border-color; 10 | $panel-inner-border: $laravel-border-color; 11 | 12 | // Brands 13 | $brand-primary: #3097D1; 14 | $brand-info: #8eb4cb; 15 | $brand-success: #2ab27b; 16 | $brand-warning: #cbb956; 17 | $brand-danger: #bf5329; 18 | 19 | // Typography 20 | $icon-font-path: "~bootstrap-sass/assets/fonts/bootstrap/"; 21 | $font-family-sans-serif: "Raleway", sans-serif; 22 | $font-size-base: 14px; 23 | $line-height-base: 1.6; 24 | $text-color: #636b6f; 25 | 26 | // Navbar 27 | $navbar-default-bg: #fff; 28 | 29 | // Buttons 30 | $btn-default-color: $text-color; 31 | 32 | // Inputs 33 | $input-border: lighten($text-color, 40%); 34 | $input-border-focus: lighten($brand-primary, 25%); 35 | $input-color-placeholder: lighten($text-color, 30%); 36 | 37 | // Panels 38 | $panel-default-heading-bg: #fff; 39 | -------------------------------------------------------------------------------- /resources/assets/sass/app.scss: -------------------------------------------------------------------------------- 1 | 2 | // Fonts 3 | @import url(https://fonts.googleapis.com/css?family=Raleway:300,400,600); 4 | 5 | // Variables 6 | @import "variables"; 7 | 8 | // Bootstrap 9 | @import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap"; 10 | -------------------------------------------------------------------------------- /resources/lang/en/auth.php: -------------------------------------------------------------------------------- 1 | 'These credentials do not match our records.', 17 | 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /resources/lang/en/pagination.php: -------------------------------------------------------------------------------- 1 | '« Previous', 17 | 'next' => 'Next »', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /resources/lang/en/passwords.php: -------------------------------------------------------------------------------- 1 | 'Passwords must be at least six characters and match the confirmation.', 17 | 'reset' => 'Your password has been reset!', 18 | 'sent' => 'We have e-mailed your password reset link!', 19 | 'token' => 'This password reset token is invalid.', 20 | 'user' => "We can't find a user with that e-mail address.", 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /resources/lang/en/validation.php: -------------------------------------------------------------------------------- 1 | 'The :attribute must be accepted.', 17 | 'active_url' => 'The :attribute is not a valid URL.', 18 | 'after' => 'The :attribute must be a date after :date.', 19 | 'after_or_equal' => 'The :attribute must be a date after or equal to :date.', 20 | 'alpha' => 'The :attribute may only contain letters.', 21 | 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', 22 | 'alpha_num' => 'The :attribute may only contain letters and numbers.', 23 | 'array' => 'The :attribute must be an array.', 24 | 'before' => 'The :attribute must be a date before :date.', 25 | 'before_or_equal' => 'The :attribute must be a date before or equal to :date.', 26 | 'between' => [ 27 | 'numeric' => 'The :attribute must be between :min and :max.', 28 | 'file' => 'The :attribute must be between :min and :max kilobytes.', 29 | 'string' => 'The :attribute must be between :min and :max characters.', 30 | 'array' => 'The :attribute must have between :min and :max items.', 31 | ], 32 | 'boolean' => 'The :attribute field must be true or false.', 33 | 'confirmed' => 'The :attribute confirmation does not match.', 34 | 'date' => 'The :attribute is not a valid date.', 35 | 'date_format' => 'The :attribute does not match the format :format.', 36 | 'different' => 'The :attribute and :other must be different.', 37 | 'digits' => 'The :attribute must be :digits digits.', 38 | 'digits_between' => 'The :attribute must be between :min and :max digits.', 39 | 'dimensions' => 'The :attribute has invalid image dimensions.', 40 | 'distinct' => 'The :attribute field has a duplicate value.', 41 | 'email' => 'The :attribute must be a valid email address.', 42 | 'exists' => 'The selected :attribute is invalid.', 43 | 'file' => 'The :attribute must be a file.', 44 | 'filled' => 'The :attribute field must have a value.', 45 | 'image' => 'The :attribute must be an image.', 46 | 'in' => 'The selected :attribute is invalid.', 47 | 'in_array' => 'The :attribute field does not exist in :other.', 48 | 'integer' => 'The :attribute must be an integer.', 49 | 'ip' => 'The :attribute must be a valid IP address.', 50 | 'json' => 'The :attribute must be a valid JSON string.', 51 | 'max' => [ 52 | 'numeric' => 'The :attribute may not be greater than :max.', 53 | 'file' => 'The :attribute may not be greater than :max kilobytes.', 54 | 'string' => 'The :attribute may not be greater than :max characters.', 55 | 'array' => 'The :attribute may not have more than :max items.', 56 | ], 57 | 'mimes' => 'The :attribute must be a file of type: :values.', 58 | 'mimetypes' => 'The :attribute must be a file of type: :values.', 59 | 'min' => [ 60 | 'numeric' => 'The :attribute must be at least :min.', 61 | 'file' => 'The :attribute must be at least :min kilobytes.', 62 | 'string' => 'The :attribute must be at least :min characters.', 63 | 'array' => 'The :attribute must have at least :min items.', 64 | ], 65 | 'not_in' => 'The selected :attribute is invalid.', 66 | 'numeric' => 'The :attribute must be a number.', 67 | 'present' => 'The :attribute field must be present.', 68 | 'regex' => 'The :attribute format is invalid.', 69 | 'required' => 'The :attribute field is required.', 70 | 'required_if' => 'The :attribute field is required when :other is :value.', 71 | 'required_unless' => 'The :attribute field is required unless :other is in :values.', 72 | 'required_with' => 'The :attribute field is required when :values is present.', 73 | 'required_with_all' => 'The :attribute field is required when :values is present.', 74 | 'required_without' => 'The :attribute field is required when :values is not present.', 75 | 'required_without_all' => 'The :attribute field is required when none of :values are present.', 76 | 'same' => 'The :attribute and :other must match.', 77 | 'size' => [ 78 | 'numeric' => 'The :attribute must be :size.', 79 | 'file' => 'The :attribute must be :size kilobytes.', 80 | 'string' => 'The :attribute must be :size characters.', 81 | 'array' => 'The :attribute must contain :size items.', 82 | ], 83 | 'string' => 'The :attribute must be a string.', 84 | 'timezone' => 'The :attribute must be a valid zone.', 85 | 'unique' => 'The :attribute has already been taken.', 86 | 'uploaded' => 'The :attribute failed to upload.', 87 | 'url' => 'The :attribute format is invalid.', 88 | 89 | /* 90 | |-------------------------------------------------------------------------- 91 | | Custom Validation Language Lines 92 | |-------------------------------------------------------------------------- 93 | | 94 | | Here you may specify custom validation messages for attributes using the 95 | | convention "attribute.rule" to name the lines. This makes it quick to 96 | | specify a specific custom language line for a given attribute rule. 97 | | 98 | */ 99 | 100 | 'custom' => [ 101 | 'attribute-name' => [ 102 | 'rule-name' => 'custom-message', 103 | ], 104 | ], 105 | 106 | /* 107 | |-------------------------------------------------------------------------- 108 | | Custom Validation Attributes 109 | |-------------------------------------------------------------------------- 110 | | 111 | | The following language lines are used to swap attribute place-holders 112 | | with something more reader friendly such as E-Mail Address instead 113 | | of "email". This simply helps us make messages a little cleaner. 114 | | 115 | */ 116 | 117 | 'attributes' => [], 118 | 119 | ]; 120 | -------------------------------------------------------------------------------- /resources/views/auth/login.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
Login
9 |
10 |
11 | {{ csrf_field() }} 12 | 13 |
14 | 15 | 16 |
17 | 18 | 19 | @if ($errors->has('email')) 20 | 21 | {{ $errors->first('email') }} 22 | 23 | @endif 24 |
25 |
26 | 27 |
28 | 29 | 30 |
31 | 32 | 33 | @if ($errors->has('password')) 34 | 35 | {{ $errors->first('password') }} 36 | 37 | @endif 38 |
39 |
40 | 41 |
42 |
43 |
44 | 47 |
48 |
49 |
50 | 51 |
52 |
53 | 56 | 57 | 58 | Forgot Your Password? 59 | 60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | @endsection 69 | -------------------------------------------------------------------------------- /resources/views/auth/passwords/email.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
Reset Password
9 |
10 | @if (session('status')) 11 |
12 | {{ session('status') }} 13 |
14 | @endif 15 | 16 |
17 | {{ csrf_field() }} 18 | 19 |
20 | 21 | 22 |
23 | 24 | 25 | @if ($errors->has('email')) 26 | 27 | {{ $errors->first('email') }} 28 | 29 | @endif 30 |
31 |
32 | 33 |
34 |
35 | 38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | @endsection 47 | -------------------------------------------------------------------------------- /resources/views/auth/passwords/reset.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
Reset Password
9 | 10 |
11 | @if (session('status')) 12 |
13 | {{ session('status') }} 14 |
15 | @endif 16 | 17 |
18 | {{ csrf_field() }} 19 | 20 | 21 | 22 |
23 | 24 | 25 |
26 | 27 | 28 | @if ($errors->has('email')) 29 | 30 | {{ $errors->first('email') }} 31 | 32 | @endif 33 |
34 |
35 | 36 |
37 | 38 | 39 |
40 | 41 | 42 | @if ($errors->has('password')) 43 | 44 | {{ $errors->first('password') }} 45 | 46 | @endif 47 |
48 |
49 | 50 |
51 | 52 |
53 | 54 | 55 | @if ($errors->has('password_confirmation')) 56 | 57 | {{ $errors->first('password_confirmation') }} 58 | 59 | @endif 60 |
61 |
62 | 63 |
64 |
65 | 68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | @endsection 77 | -------------------------------------------------------------------------------- /resources/views/auth/register.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
Register
9 |
10 |
11 | {{ csrf_field() }} 12 | 13 |
14 | 15 | 16 |
17 | 18 | 19 | @if ($errors->has('name')) 20 | 21 | {{ $errors->first('name') }} 22 | 23 | @endif 24 |
25 |
26 | 27 |
28 | 29 | 30 |
31 | 32 | 33 | @if ($errors->has('email')) 34 | 35 | {{ $errors->first('email') }} 36 | 37 | @endif 38 |
39 |
40 | 41 |
42 | 43 | 44 |
45 | 46 | 47 | @if ($errors->has('password')) 48 | 49 | {{ $errors->first('password') }} 50 | 51 | @endif 52 |
53 |
54 | 55 |
56 | 57 | 58 |
59 | 60 |
61 |
62 | 63 |
64 |
65 | 68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 | @endsection 77 | -------------------------------------------------------------------------------- /resources/views/home.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
Dashboard
8 | 9 |
10 | 11 |

12 | 13 |

14 | 15 | 16 | 17 | @role('Admin') 18 |

Visit roles and give permissions for each roles.

19 | @endrole 20 | 21 |

 
22 |

Assign different roles to users and login from different browsers
23 | to see access control and authorization at work.

24 |
25 |
26 |
27 |
28 | @endsection 29 | -------------------------------------------------------------------------------- /resources/views/layouts/app.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | @yield('title') {{ config('app.name', 'Laravel') }} 12 | 13 | 14 | {{-- --}} 15 | 16 | 17 | 20 | 21 | 26 | 27 | 28 |
29 | 111 | 112 |
113 |
114 | @include('flash::message') 115 |
116 | @yield('content') 117 |
118 |
119 | 120 | 121 | 122 | 123 | @stack('scripts') 124 | 125 | 131 | 132 | 133 | -------------------------------------------------------------------------------- /resources/views/post/_form.blade.php: -------------------------------------------------------------------------------- 1 | 2 |
3 | {!! Form::label('title', 'Title') !!} 4 | {!! Form::text('title', null, ['class' => 'form-control', 'placeholder' => 'Title of Post']) !!} 5 | @if ($errors->has('title'))

{{ $errors->first('title') }}

@endif 6 |
7 | 8 | 9 |
10 | {!! Form::label('body', 'Body') !!} 11 | {!! Form::textarea('body', null, ['class' => 'form-control ckeditor', 'placeholder' => 'Body of Post...']) !!} 12 | @if ($errors->has('body'))

{{ $errors->first('body') }}

@endif 13 |
14 | 15 | @push('scripts') 16 | 17 | @endpush -------------------------------------------------------------------------------- /resources/views/post/edit.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('title', 'Edit Post ') 4 | 5 | @section('content') 6 | 7 |
8 |
9 |

Edit

10 |
11 |
12 | Back 13 |
14 |
15 | 16 |
17 |
18 |
19 |
20 |
21 | {!! Form::model($post, ['method' => 'PUT', 'route' => ['posts.update', $post->id ] ]) !!} 22 | @include('post._form') 23 | 24 | {!! Form::submit('Save Changes', ['class' => 'btn btn-primary']) !!} 25 | {!! Form::close() !!} 26 |
27 |
28 |
29 |
30 |
31 | @endsection -------------------------------------------------------------------------------- /resources/views/post/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('title', 'Posts') 4 | 5 | @section('content') 6 |
7 |
8 | 9 |
10 |
11 | @can('add_posts') 12 | Create 13 | @endcan 14 |
15 |
16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | @can('edit_posts', 'delete_posts') 26 | 27 | @endcan 28 | 29 | 30 | 31 | @foreach($result as $item) 32 | 33 | 34 | 35 | 36 | 37 | @can('edit_posts', 'delete_posts') 38 | 44 | @endcan 45 | 46 | @endforeach 47 | 48 |
IdTitleAuthorCreated AtActions
{{ $item->id }}{{ $item->title }}{{ $item->user['name'] }}{{ $item->created_at->toFormattedDateString() }} 39 | @include('shared._actions', [ 40 | 'entity' => 'posts', 41 | 'id' => $item->id 42 | ]) 43 |
49 | 50 |
51 | {{ $result->links() }} 52 |
53 |
54 | 55 | @endsection -------------------------------------------------------------------------------- /resources/views/post/new.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('title', 'Create') 4 | 5 | @section('content') 6 | 7 |
8 |
9 |

Create

10 |
11 |
12 | Back 13 |
14 |
15 | 16 |
17 |
18 | {!! Form::open(['route' => ['posts.store'] ]) !!} 19 | @include('post._form') 20 | 21 | {!! Form::submit('Create', ['class' => 'btn btn-primary']) !!} 22 | {!! Form::close() !!} 23 |
24 |
25 | @endsection -------------------------------------------------------------------------------- /resources/views/role/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('title', 'Roles & Permissions') 4 | 5 | @section('content') 6 | 7 | 8 | 35 | 36 |
37 |
38 |

Roles

39 |
40 |
41 | @can('add_roles') 42 | New 43 | @endcan 44 |
45 |
46 | 47 | 48 | @forelse ($roles as $role) 49 | {!! Form::model($role, ['method' => 'PUT', 'route' => ['roles.update', $role->id ], 'class' => 'm-b']) !!} 50 | 51 | @if($role->name === 'Admin') 52 | @include('shared._permissions', [ 53 | 'title' => $role->name .' Permissions', 54 | 'options' => ['disabled'] ]) 55 | @else 56 | @include('shared._permissions', [ 57 | 'title' => $role->name .' Permissions', 58 | 'model' => $role ]) 59 | @can('edit_roles') 60 | {!! Form::submit('Save', ['class' => 'btn btn-primary']) !!} 61 | @endcan 62 | @endif 63 | 64 | {!! Form::close() !!} 65 | 66 | @empty 67 |

No Roles defined, please run php artisan db:seed to seed some dummy data.

68 | @endforelse 69 | @endsection -------------------------------------------------------------------------------- /resources/views/shared/_actions.blade.php: -------------------------------------------------------------------------------- 1 | @can('edit_'.$entity) 2 | 3 | Edit 4 | @endcan 5 | 6 | @can('delete_'.$entity) 7 | {!! Form::open( ['method' => 'delete', 'url' => route($entity.'.destroy', ['user' => $id]), 'style' => 'display: inline', 'onSubmit' => 'return confirm("Are yous sure wanted to delete it?")']) !!} 8 | 11 | {!! Form::close() !!} 12 | @endcan 13 | -------------------------------------------------------------------------------- /resources/views/shared/_permissions.blade.php: -------------------------------------------------------------------------------- 1 |
2 | 9 |
10 |
11 |
12 | @foreach($permissions as $perm) 13 | hasPermissionTo($perm->name); 18 | } 19 | 20 | if( isset($user)) { 21 | $per_found = $user->hasDirectPermission($perm->name); 22 | } 23 | ?> 24 | 25 |
26 |
27 | 30 |
31 |
32 | @endforeach 33 |
34 |
35 |
36 |
-------------------------------------------------------------------------------- /resources/views/user/_form.blade.php: -------------------------------------------------------------------------------- 1 | 2 |
3 | {!! Form::label('name', 'Name') !!} 4 | {!! Form::text('name', null, ['class' => 'form-control', 'placeholder' => 'Name']) !!} 5 | @if ($errors->has('name'))

{{ $errors->first('name') }}

@endif 6 |
7 | 8 | 9 |
10 | {!! Form::label('email', 'Email') !!} 11 | {!! Form::text('email', null, ['class' => 'form-control', 'placeholder' => 'Email']) !!} 12 | @if ($errors->has('email'))

{{ $errors->first('email') }}

@endif 13 |
14 | 15 | 16 |
17 | {!! Form::label('password', 'Password') !!} 18 | {!! Form::password('password', ['class' => 'form-control', 'placeholder' => 'Password']) !!} 19 | @if ($errors->has('password'))

{{ $errors->first('password') }}

@endif 20 |
21 | 22 | 23 |
24 | {!! Form::label('roles[]', 'Roles') !!} 25 | {!! Form::select('roles[]', $roles, isset($user) ? $user->roles->pluck('id')->toArray() : null, ['class' => 'form-control', 'multiple']) !!} 26 | @if ($errors->has('roles'))

{{ $errors->first('roles') }}

@endif 27 |
28 | 29 | 30 | @if(isset($user)) 31 | @include('shared._permissions', ['closed' => 'true', 'model' => $user ]) 32 | @endif -------------------------------------------------------------------------------- /resources/views/user/edit.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('title', 'Edit User ' . $user->first_name) 4 | 5 | @section('content') 6 | 7 |
8 |
9 |

Edit {{ $user->first_name }}

10 |
11 |
12 | Back 13 |
14 |
15 | 16 |
17 |
18 |
19 |
20 |
21 | {!! Form::model($user, ['method' => 'PUT', 'route' => ['users.update', $user->id ] ]) !!} 22 | @include('user._form') 23 | 24 | {!! Form::submit('Save Changes', ['class' => 'btn btn-primary']) !!} 25 | {!! Form::close() !!} 26 |
27 |
28 |
29 |
30 |
31 | @endsection -------------------------------------------------------------------------------- /resources/views/user/index.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('title', 'Users') 4 | 5 | @section('content') 6 |
7 |
8 | 9 |
10 |
11 | @can('add_users') 12 | Create 13 | @endcan 14 |
15 |
16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | @can('edit_users', 'delete_users') 27 | 28 | @endcan 29 | 30 | 31 | 32 | @foreach($result as $item) 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | @can('edit_users') 41 | 47 | @endcan 48 | 49 | @endforeach 50 | 51 |
IdNameEmailRoleCreated AtActions
{{ $item->id }}{{ $item->name }}{{ $item->email }}{{ $item->roles->implode('name', ', ') }}{{ $item->created_at->toFormattedDateString() }} 42 | @include('shared._actions', [ 43 | 'entity' => 'users', 44 | 'id' => $item->id 45 | ]) 46 |
52 | 53 |
54 | {{ $result->links() }} 55 |
56 |
57 | 58 | @endsection -------------------------------------------------------------------------------- /resources/views/user/new.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('title', 'Create') 4 | 5 | @section('content') 6 | 7 |
8 |
9 |

Create

10 |
11 |
12 | Back 13 |
14 |
15 | 16 |
17 |
18 | {!! Form::open(['route' => ['users.store'] ]) !!} 19 | @include('user._form') 20 | 21 | {!! Form::submit('Create', ['class' => 'btn btn-primary']) !!} 22 | {!! Form::close() !!} 23 |
24 |
25 | @endsection -------------------------------------------------------------------------------- /resources/views/welcome.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Laravel 9 | 10 | 11 | 12 | 13 | 14 | 75 | 76 | 77 |
78 | @if (Route::has('login')) 79 | 87 | @endif 88 | 89 |
90 |
91 | Laravel
Role Permissions 92 |
93 | 94 | 97 |
98 |
99 | 100 |
101 | 102 | 103 | 104 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /routes/api.php: -------------------------------------------------------------------------------- 1 | get('/user', function (Request $request) { 17 | return $request->user(); 18 | }); 19 | -------------------------------------------------------------------------------- /routes/channels.php: -------------------------------------------------------------------------------- 1 | id === (int) $id; 16 | }); 17 | -------------------------------------------------------------------------------- /routes/console.php: -------------------------------------------------------------------------------- 1 | comment(Inspiring::quote()); 18 | })->describe('Display an inspiring quote'); 19 | -------------------------------------------------------------------------------- /routes/web.php: -------------------------------------------------------------------------------- 1 | name('home'); 21 | 22 | Route::group( ['middleware' => ['auth']], function() { 23 | Route::resource('users', 'UserController'); 24 | Route::resource('roles', 'RoleController'); 25 | Route::resource('posts', 'PostController'); 26 | }); 27 | -------------------------------------------------------------------------------- /server.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | $uri = urldecode( 11 | parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) 12 | ); 13 | 14 | // This file allows us to emulate Apache's "mod_rewrite" functionality from the 15 | // built-in PHP web server. This provides a convenient way to test a Laravel 16 | // application without having installed a "real" web server software here. 17 | if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) { 18 | return false; 19 | } 20 | 21 | require_once __DIR__.'/public/index.php'; 22 | -------------------------------------------------------------------------------- /storage/app/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !public/ 3 | !.gitignore 4 | -------------------------------------------------------------------------------- /storage/app/public/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/.gitignore: -------------------------------------------------------------------------------- 1 | config.php 2 | routes.php 3 | schedule-* 4 | compiled.php 5 | services.json 6 | events.scanned.php 7 | routes.scanned.php 8 | down 9 | -------------------------------------------------------------------------------- /storage/framework/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/sessions/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/testing/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/framework/views/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /tests/CreatesApplication.php: -------------------------------------------------------------------------------- 1 | make(Kernel::class)->bootstrap(); 19 | 20 | return $app; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/Feature/ExampleTest.php: -------------------------------------------------------------------------------- 1 | get('/'); 20 | 21 | $response->assertStatus(200); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | assertTrue(true); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /webpack.mix.js: -------------------------------------------------------------------------------- 1 | const { mix } = require('laravel-mix'); 2 | 3 | /* 4 | |-------------------------------------------------------------------------- 5 | | Mix Asset Management 6 | |-------------------------------------------------------------------------- 7 | | 8 | | Mix provides a clean, fluent API for defining some Webpack build steps 9 | | for your Laravel application. By default, we are compiling the Sass 10 | | file for the application as well as bundling up all the JS files. 11 | | 12 | */ 13 | 14 | mix.js('resources/assets/js/app.js', 'public/js') 15 | .sass('resources/assets/sass/app.scss', 'public/css'); 16 | --------------------------------------------------------------------------------