Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
78006b5
Fixed typo
nasrulhazim Apr 24, 2018
5b41e0f
Added meta config & component.
nasrulhazim Apr 24, 2018
31fd971
Added as() in api and datatable map route.
nasrulhazim Apr 24, 2018
7b8d3f1
Added Custom API Accept Header
nasrulhazim Apr 24, 2018
233b04e
Added API Config
nasrulhazim Apr 24, 2018
43b3eaf
Added User API and Datatable Route and Controller
nasrulhazim Apr 24, 2018
7ec535b
Added ziggy
nasrulhazim Apr 24, 2018
38be7cb
refactor scripts to a component
nasrulhazim Apr 24, 2018
5535331
Added Preloader
nasrulhazim Apr 24, 2018
4817d6c
Reorganise layouts.
nasrulhazim Apr 24, 2018
b0bf319
Customise Breadcrumb
nasrulhazim Apr 24, 2018
414a95a
Refactor Axios and Preloader
nasrulhazim Apr 24, 2018
d31f199
Added Macros: Route, Model and Response
nasrulhazim Apr 24, 2018
0a0a2a7
Refactor Observer Setup
nasrulhazim Apr 24, 2018
ec10073
Fixed typo
nasrulhazim Apr 24, 2018
ab5ace5
Setting Up User Management Base.
nasrulhazim Apr 24, 2018
200c03e
fixed double nav
nasrulhazim Apr 24, 2018
08b7709
Recompile front end assets
nasrulhazim Apr 24, 2018
c08260e
Added dynamic datatable variable name
nasrulhazim Apr 24, 2018
dac8179
Added Datatable to Users Management
nasrulhazim Apr 24, 2018
68133ea
Added modals component
nasrulhazim Apr 24, 2018
3ebeacb
Set datatable own middleware.
nasrulhazim Apr 24, 2018
c890517
HIde preloader by default.
nasrulhazim Apr 24, 2018
ad696ce
Reorganise scripts.
nasrulhazim Apr 24, 2018
8a2ac8e
Added show modals and scripts for users management.
nasrulhazim Apr 24, 2018
5e97021
Get User's Details via API
nasrulhazim Apr 24, 2018
e3df10b
Added error pages.
nasrulhazim Apr 24, 2018
c38ebad
Added Navigation for Management.
nasrulhazim Apr 25, 2018
7f756de
Clean up codes to support multilingual - use __() helper.
nasrulhazim Apr 25, 2018
5bdcb6b
Apply PHP CS Fixer
nasrulhazim Apr 25, 2018
e5de49d
Added thepinecode/i18n for js i18n
nasrulhazim Apr 25, 2018
4f44d7a
Update axios interceptor to handle errors automatically.
nasrulhazim Apr 25, 2018
3967d34
Added created at and update at field in table lang.
nasrulhazim Apr 25, 2018
72dff6f
Added standard action buttons
nasrulhazim Apr 25, 2018
bf5f2b0
Added MinifyHtml Middleware
nasrulhazim Apr 25, 2018
d4053af
Update datatable variable name.
nasrulhazim Apr 25, 2018
412dc6b
Added input and select form component
nasrulhazim Apr 25, 2018
f49e86b
Update modal's button component
nasrulhazim Apr 25, 2018
c29bd69
Make use of @isset directive for table component
nasrulhazim Apr 25, 2018
18d8b9e
Remove unused views.
nasrulhazim Apr 25, 2018
f217a1e
Added create user form
nasrulhazim Apr 25, 2018
f50ef72
Added create user modal and update show modal form.
nasrulhazim Apr 25, 2018
2fab3b8
Added Show and Destroy User
nasrulhazim Apr 25, 2018
e482e8e
Apply PHP CS Fixer
nasrulhazim Apr 25, 2018
3f3df5b
Allow custom name and id for input
nasrulhazim Apr 25, 2018
5f40890
Added Store User API
nasrulhazim Apr 25, 2018
a81731d
Create new user.
nasrulhazim Apr 25, 2018
75e4b9d
Refactor UI
nasrulhazim Apr 25, 2018
4f2a096
Added popover component
nasrulhazim Apr 25, 2018
b9cd271
Refactor datatable component
nasrulhazim Apr 25, 2018
4d790ef
Added HasDatatable trait and roles to string in user's model.
nasrulhazim Apr 26, 2018
8205372
Added roles_to_string field.
nasrulhazim Apr 26, 2018
1e49785
Show hashslug in datatable.
nasrulhazim Apr 26, 2018
d595ea7
Added select2 multiple component.
nasrulhazim Apr 26, 2018
4afed00
Added style partial.
nasrulhazim Apr 26, 2018
288445a
Remove edit & create user form.
nasrulhazim Apr 26, 2018
8907241
Refactor Create and Update user form.
nasrulhazim Apr 26, 2018
800bfa6
Allow custom id and name for form components.
nasrulhazim Apr 26, 2018
b030675
Allow custom id and name for form components.
nasrulhazim Apr 26, 2018
0093d12
Centralise form.
nasrulhazim Apr 26, 2018
e5ac417
Allow update or store API
nasrulhazim Apr 26, 2018
890a933
Adden hidden component
nasrulhazim Apr 26, 2018
b33bc0f
Done update user
nasrulhazim Apr 26, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Login details for default users:

1. E-mail : **developer@app.com** Password: `developer`
2. E-mail : **administrator@app.com** Password: `administrator`
3. 1. E-mail : **user@app.com** Password: `user`
3. E-mail : **user@app.com** Password: `user`

By default, all newly registered user will be assign role as `user`.

Expand Down
15 changes: 15 additions & 0 deletions app/Http/Controllers/Api/Datatable/Manage/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Http\Controllers\Api\Datatable\Manage;

use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;

class UserController extends Controller
{
public function __invoke(Request $request)
{
return app('datatables')->eloquent(User::datatable())->toJson();
}
}
119 changes: 119 additions & 0 deletions app/Http/Controllers/Api/Manage/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php

namespace App\Http\Controllers\Api\Manage;

use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Auth\Events\Registered;

class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
$data = $request->only('name', 'email', 'password');
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
event(new Registered($user));
$user->syncRoles([$request->role]);
return response()->api([], __('User successfully stored.'), true, 201);
}

/**
* Display the specified resource.
*
* @param string $id
*
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$user = User::details()->findByHashSlug($id);

/**
* @todo should have a transformer to do this.
*/
$user = collect($user->only('name', 'email', 'roles_to_string', 'roles'));
$roles = $user->get('roles')->mapWithKeys(function($role){
return [$role->id => $role->name];
});
$user->put('roles', $roles);

return response()->api($user);
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param string $id
*
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$this->validate($request, [
'name' => 'required|string|max:255',
]);

$fields = $request->only('name');

if(!empty($request->input('password'))) {
$this->validate($request, [
'password' => 'required|string|min:6|confirmed',
]);
$fields['password'] = bcrypt($request->input('password'));
}

$user = User::findByHashSlug($id);
$user->update($fields);
$user->syncRoles($request->input('roles'));

return response()->api([], __('User successfully updated.'), true, 201);
}

/**
* Remove the specified resource from storage.
*
* @param string $id
*
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
if ($id == user()->hashslug) {
return response()->api([], __('You cannot delete yourself!'), false, 401);
}
$user = User::findByHashSlug($id);
if ($user->hasRole('developer')) {
return response()->api([], __('Trust me, don\'t kill your developer!'), false, 401);
}
$user->delete();

return response()->api([], __('You have successfully delete a user.'));
}
}
57 changes: 57 additions & 0 deletions app/Http/Controllers/Manage/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Http\Controllers\Manage;

use App\Http\Controllers\Controller;
use App\Models\User;

class UserController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return view('manage.users.index');
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('manage.users.create');
}

/**
* Display the specified resource.
*
* @param string $id
*
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$user = User::findByHashSlug($id);

return view('manage.users.show', compact('user'));
}

/**
* Show the form for editing the specified resource.
*
* @param string $id
*
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$user = User::findByHashSlug($id);

return view('manage.users.edit');
}
}
8 changes: 8 additions & 0 deletions app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,16 @@ class Kernel extends HttpKernel
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
\Spatie\Referer\CaptureReferer::class,
\Laravel\Passport\Http\Middleware\CreateFreshApiToken::class,
],

'api' => [
\App\Http\Middleware\ApiHeader::class,
'throttle:60,1',
'bindings',
],

'datatable' => [
'throttle:60,1',
'bindings',
],
Expand All @@ -60,5 +67,6 @@ class Kernel extends HttpKernel
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
'minify' => \App\Http\Middleware\MinifyHtml::class,
];
}
25 changes: 25 additions & 0 deletions app/Http/Middleware/ApiHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Http\Middleware;

use Closure;

class ApiHeader
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
if (config('api.header.accept') != $request->header('Accept')) {
return response()->json(['message' => 'Invalid Accept Header'], 400);
}

return $next($request);
}
}
24 changes: 24 additions & 0 deletions app/Http/Middleware/MinifyHtml.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Http\Middleware;

use Closure;

class MinifyHtml
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
$response->setContent(minify($response->getContent()));

return $response;
}
}
28 changes: 28 additions & 0 deletions app/Macros/Http/Response.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Macros\Http;

use Illuminate\Support\Facades\Response as HttpResponse;

class Response
{
public static function registerMacros()
{
HttpResponse::macro('api', function ($data, $message = null, $status = true, $code = 200) {
return response()->json([
'data' => $data,
'message' => $message,
'status' => $status,
'code' => $code,
], $code);
});

HttpResponse::macro('datatable', function ($data, $countRecordsFiltered, $countRecordsTotal) {
return response()->json([
'recordsFiltered' => $countRecordsFiltered,
'recordsTotal' => $countRecordsTotal,
'data' => $data,
]);
});
}
}
19 changes: 19 additions & 0 deletions app/Macros/Models/Model.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Macros\Models;

use Illuminate\Database\Eloquent\Builder;

class Model
{
public static function registerMacros()
{
Builder::macro('hashslug', function ($hashslug) {
return $this->where('hashslug', $hashslug);
});

Builder::macro('findByHashSlug', function ($hashslug) {
return $this->hashslug($hashslug)->firstOrFail();
});
}
}
17 changes: 17 additions & 0 deletions app/Macros/Routing/Route.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Macros\Routing;

// use Illuminate\Support\Facades\Route as DefaultRoute;

class Route
{
public static function registerMacros()
{
// if (! DefaultRoute::hasMacro('name')) {
// DefaultRoute::macro('name', function ($modules) {

// });
// }
}
}
Loading