|
| 1 | +# Now-Ui Frontend Preset For Laravel Framework 5.5 and Up |
| 2 | + |
| 3 | +Now-Ui Frontend Preset For Laravel Framework 5.5 and Up |
| 4 | + |
| 5 | +*Current version*: NowUi v1.0.10. More info at https://www.creative-tim.com/product/now-ui-dashboard-laravel. |
| 6 | + |
| 7 | +## Note |
| 8 | + |
| 9 | +We recommend installing this preset on a project that you are starting from scratch, otherwise your project's design might break. |
| 10 | + |
| 11 | +## Prerequisites |
| 12 | + |
| 13 | +If you don't already have an Apache local environment with PHP and MySQL, use one of the following links: |
| 14 | + |
| 15 | + - Windows: https://updivision.com/blog/post/beginner-s-guide-to-setting-up-your-local-development-environment-on-windows |
| 16 | + - Linux: https://howtoubuntu.org/how-to-install-lamp-on-ubuntu |
| 17 | + - Mac: https://wpshout.com/quick-guides/how-to-install-mamp-on-your-mac/ |
| 18 | + |
| 19 | +Also, you will need to install Composer: https://getcomposer.org/doc/00-intro.md |
| 20 | +And Laravel: https://laravel.com/docs/5.8/installation |
| 21 | + |
| 22 | +## Installation |
| 23 | + |
| 24 | +After initializing a fresh instance of Laravel (and making all the necessary configurations), install the preset using one of the provided methods: |
| 25 | + |
| 26 | +### Via composer |
| 27 | + |
| 28 | +1. `Cd` to your Laravel app |
| 29 | +2. Install this preset via `composer require laravel-frontend-presets/NowUi`. No need to register the service provider. Laravel 5.5 & up can auto detect the package. |
| 30 | +3. Run `php artisan preset now-ui` command to install the Now-Ui preset. This will install all the necessary assets and also the custom auth views, it will also add the auth route in `routes/web.php` |
| 31 | +(NOTE: If you run this command several times, be sure to clean up the duplicate Auth entries in routes/web.php) |
| 32 | +4. In your terminal run `composer dump-autoload` |
| 33 | +5. Run `php artisan migrate --seed` to create basic users table |
| 34 | + |
| 35 | +### By using the archive |
| 36 | + |
| 37 | +1. In your application's root create a **presets** folder |
| 38 | +2. [Download an archive](https://github.com/laravel-frontend-presets/now-ui/archive/master.zip) of the repo and unzip it |
| 39 | +3. Copy and paste **now-ui-master** folder in presets (created in step 2) and rename it to **now-ui** |
| 40 | +4. Open `composer.json` file |
| 41 | +5. Add `"LaravelFrontendPresets\\NowUiPreset\\": "presets/NowUi/src"` to `autoload/psr-4` and to `autoload-dev/psr-4` |
| 42 | +6. Add `LaravelFrontendPresets\NowUiPreset\NowUiPresetServiceProvider::class` to `config/app.php` file |
| 43 | +7. In your terminal run `composer dump-autoload` |
| 44 | +8. Run `php artisan preset now-ui` command to install the NowUi preset. This will install all the necessary assets and also the custom auth views, it will also add the auth route in `routes/web.php` |
| 45 | +(NOTE: If you run this command several times, be sure to clean up the duplicate Auth entries in routes/web.php) |
| 46 | +9. Run `php artisan migrate --seed` to create basic users table |
| 47 | + |
| 48 | + |
| 49 | +## Usage |
| 50 | + |
| 51 | +Register a user or login using **[email protected]** and **secret ** and start testing the preset (make sure to run the migrations and seeders for these credentials to be available). |
| 52 | + |
| 53 | +Besides the dashboard and the auth pages this preset also has a user management example and an edit profile page. All the necessary files (controllers, requests, views) are installed out of the box and all the needed routes are added to `routes/web.php`. Keep in mind that all of the features can be viewed once you login using the credentials provided above or by registering your own user. |
| 54 | + |
| 55 | +### Dashboard |
| 56 | + |
| 57 | +You can access the dashboard either by using the "**Dashboard**" link in the left sidebar or by adding **/home** in the url. |
| 58 | + |
| 59 | +### Profile edit |
| 60 | + |
| 61 | +You have the option to edit the current logged in user's profile (change name, email and password). To access this page just click the "**User profile**" link in the left sidebar or by adding **/profile** in the url. |
| 62 | + |
| 63 | +The `App\Htttp\Controlers\ProfileController` handles the update of the user information. |
| 64 | + |
| 65 | +``` |
| 66 | +public function update(ProfileRequest $request) |
| 67 | +{ |
| 68 | + auth()->user()->update($request->all()); |
| 69 | +
|
| 70 | + return back()->withStatus(__('Profile successfully updated.')); |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +Also you shouldn't worry about entering wrong data in the inputs when editing the profile, validation rules were added to prevent this (see `App\Http\Requests\ProfileRequest`). If you try to change the password you will see that other validation rules were added in `App\Http\Requests\PasswordRequest`. Notice that in this file you have a custom validation rule that can be found in `App\Rules\CurrentPasswordCheckRule`. |
| 75 | + |
| 76 | +``` |
| 77 | +public function rules() |
| 78 | +{ |
| 79 | + return [ |
| 80 | + 'old_password' => ['required', 'min:6', new CurrentPasswordCheckRule], |
| 81 | + 'password' => ['required', 'min:6', 'confirmed', 'different:old_password'], |
| 82 | + 'password_confirmation' => ['required', 'min:6'], |
| 83 | + ]; |
| 84 | +} |
| 85 | +``` |
| 86 | + |
| 87 | +### User management |
| 88 | + |
| 89 | +The preset comes with a user management option out of the box. To access this click the "**User Management**" link in the left sidebar or add **/user** to the url. |
| 90 | +The first thing you will see is the listing of the existing users. You can add new ones by clicking the "**Add user**" button (above the table on the right). On the Add user page you will see the form that allows you to do this. All pages are generate using blade templates: |
| 91 | + |
| 92 | +``` |
| 93 | +<div class="form-group{{ $errors->has('name') ? ' has-danger' : '' }}"> |
| 94 | + <label class="form-control-label" for="input-name">{{ __('Name') }}</label> |
| 95 | + <input type="text" name="name" id="input-name" class="form-control form-control-alternative{{ $errors->has('name') ? ' is-invalid' : '' }}" placeholder="{{ __('Name') }}" value="{{ old('name') }}" required autofocus> |
| 96 | +
|
| 97 | + @if ($errors->has('name')) |
| 98 | + <span class="invalid-feedback" role="alert"> |
| 99 | + <strong>{{ $errors->first('name') }}</strong> |
| 100 | + </span> |
| 101 | + @endif |
| 102 | +</div> |
| 103 | +``` |
| 104 | + |
| 105 | +Also validation rules were added so you will know exactely what to enter in the form fields (see `App\Http\Requests\UserRequest`). Note that these validation rules also apply for the user edit option. |
| 106 | + |
| 107 | +``` |
| 108 | +public function rules() |
| 109 | +{ |
| 110 | + return [ |
| 111 | + 'name' => [ |
| 112 | + 'required', 'min:3' |
| 113 | + ], |
| 114 | + 'email' => [ |
| 115 | + 'required', 'email', Rule::unique((new User)->getTable())->ignore($this->route()->user->id ?? null) |
| 116 | + ], |
| 117 | + 'password' => [ |
| 118 | + $this->route()->user ? 'nullable' : 'required', 'confirmed', 'min:6' |
| 119 | + ] |
| 120 | + ]; |
| 121 | +} |
| 122 | +``` |
| 123 | + |
| 124 | +Once you add more users, the list will get bigger and for every user you will have edit and delete options (access these options by clicking the three dotted menu that appears at the end of every line). |
| 125 | + |
| 126 | +All the sample code for the user management can be found in `App\Http\Controllers\UserController`. See store method example bellow: |
| 127 | + |
| 128 | +``` |
| 129 | +public function store(UserRequest $request, User $model) |
| 130 | +{ |
| 131 | + $model->create($request->merge(['password' => Hash::make($request->get('password'))])->all()); |
| 132 | +
|
| 133 | + return redirect()->route('user.index')->withStatus(__('User successfully created.')); |
| 134 | +} |
| 135 | +``` |
| 136 | + |
| 137 | +## Change log |
| 138 | + |
| 139 | +Please see the [changelog](changelog.md) for more information on what has changed recently. |
| 140 | + |
| 141 | +## Credits |
| 142 | + |
| 143 | +- [Creative Tim](https://creative-tim.com/) |
| 144 | +- [Updivision](https://updivision.com) |
| 145 | + |
| 146 | +## License |
| 147 | + |
| 148 | +[MIT License](https://github.com/laravel-frontend-presets/NowUi/blob/master/license.md). |
| 149 | + |
| 150 | +## Screen shots |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | + |
0 commit comments