Extending Modules

Overwriting views

If you want to extend one of the modules and add new fields (or remove some) you will need to overwrite the views first. To do that just copy a view from the vendor folder to the resources folder:
To edit theadmin/userview simply copy vendor/taffovelikoff/hotcoffee/resources/views/admin/user.blade.php to resources/views/vendor/hotcoffee/admin/user.blade.php

Extending the user module

If you need to add more fields in the user module you first have to copy the user.blade.php from vendor/taffovelikoff/hotcoffee/resources/views/admin to resources/views/vendor/hotcoffee/admin and add your new field where you desire (for example right after "job title"):
1
<!-- Job Title -->
2
<div class="col-lg-6">
3
<div class="form-group">
4
<label class="form-control-label" for="input-last-name">{{ __('hotcoffee::admin.user_job') }}</label>
5
<div @if($errors->has('job_title')) class="has-danger" @endif>
6
<input type="text" name="job_title" id="input-last-name" class="form-control form-control-alternative @if($errors->has('job_title')) is-invalid-alt @endif" @if(session('post')) value="{{ session('post.job_title') }}" @elseif(isset($edit)) value="{{ $edit->address->job_title }}" @endif>
7
</div>
8
</div>
9
</div>
10
11
<!-- NEW FIELD -->
12
<!-- Phone -->
13
<div class="col-lg-6">
14
<div class="form-group">
15
<label class="form-control-label" for="input-phone">Phone Number</label>
16
<div @if($errors->has('phone')) class="has-danger" @endif>
17
<input type="text" name="phone" id="input-phone" class="form-control form-control-alternative @if($errors->has('phone')) is-invalid-alt @endif" @if(session('post')) value="{{ session('post.phone') }}" @elseif(isset($edit)) value="{{ $edit->address->phone}}" @endif>
18
</div>
19
</div>
20
</div>
Copied!
It's recommended to keep the user information in the user_address table, instead of the users table. Now create a migration to add the new fields to the table.
1
php artisan make:migration add_surname_field_to_user_addresses_table
Copied!
1
<?php
2
3
use Illuminate\Database\Migrations\Migration;
4
use Illuminate\Database\Schema\Blueprint;
5
use Illuminate\Support\Facades\Schema;
6
7
class AddPhoneFieldToUserAddressesTable extends Migration
8
{
9
/**
10
* Run the migrations.
11
*
12
* @return void
13
*/
14
public function up()
15
{
16
Schema::table('user_addresses', function (Blueprint $table) {
17
$table->string('phone')->nullable();
18
});
19
}
20
21
/**
22
* Reverse the migrations.
23
*
24
* @return void
25
*/
26
public function down()
27
{
28
Schema::table('user_addresses', function (Blueprint $table) {
29
$table->dropColumn('phone');
30
});
31
}
32
}
Copied!
Now you need to publish the user configuration file:
1
php artisan vendor:publish --tag=hotcoffee_config_users
Copied!
In this file you can change some user configurations, but most importantly you can change the UserAddress namespace.
1
return [
2
3
/*
4
|--------------------------------------------------------------------------
5
| User Address Model
6
|--------------------------------------------------------------------------
7
| This allows to extend the model.
8
|
9
*/
10
11
'address_model' => \App\Models\UserAddress,
12
Copied!
Now create a new UserAddress model and populate the fillable attribute.
1
<?php
2
3
namespace App\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class UserAddress extends Model
8
{
9
protected $fillable = ['city', 'country', 'job_title', 'company', 'bio', 'phone'];
10
}
11
Copied!
If you need to do some validations you can add the rules and messages again in the users.php config file:
1
/*
2
|--------------------------------------------------------------------------
3
| Additional validation rules
4
|--------------------------------------------------------------------------
5
| Any additional validation rules and messages when updating or creating
6
| user. You can also overwrite the defaults.
7
*/
8
9
'validations' => [
10
'normal' => [
11
'phone' => 'required', // This will add a new validation for "phone".
12
],
13
'translatable' => [], // Add rules for translatable fields heree
14
],
15
16
'messages' => [
17
'normal' => [
18
'phone.required' => 'Please provide a phone number.',
19
],
20
'translatable' => [], // Add messages for translatable fields heree
21
],
Copied!
If you need to do something very specific you can copy the UserController.php from vendor/taffovelikoff/hotcoffee/src/Http/Controllers/Admin to app/Http/Controllers/Admin and re-define all the routes in your routes/web.php:
1
<?php
2
/**
3
* ADMIN
4
* Below are all custom admin routes for your application.
5
*/
6
HotCoffee::routes();
7
8
Route::group(['prefix' => config('hotcoffee.prefix'), 'middleware' => ['hotcoffee']], function () {
9
10
// Dashboard
11
Route::get('/dashboard', 'Admin\[email protected]')->name('hotcoffee.admin.dashboard');
12
13
// ===== OVERWRITING USERS MODULE ROUTES ===== //
14
15
// Users (keep route names the same)
16
Route::group(['prefix' => 'users'], function () {
17
Route::get('/', 'Admin\[email protected]')->name('hotcoffee.admin.users.index');
18
19
Route::get('/create', 'Admin\[email protected]')->name('hotcoffee.admin.users.create');
20
Route::post('/', 'Admin\[email protected]')->name('hotcoffee.admin.users.store');
21
22
Route::get('/{user}', 'Admin\[email protected]')->name('hotcoffee.admin.users.edit');
23
Route::post('/{user}', 'Admin\[email protected]')->name('hotcoffee.admin.users.update');
24
25
Route::delete('/{user}', 'Admin\[email protected]')->name('hotcoffee.admin.users.destroy');
26
});
27
});
Copied!
Now the admin panel will use the controller from the app/Http/Controllers/Admin folder, instead the one in vendor/taffovelikoff/hotcoffee/src/Http/Controllers/Admin meaning you can edit the controller.
If you are not sure about the route names of a module you can check them either with php artisan route:list or open vendor/taffovelikoff/hotcoffee/routes/web.php.

Extending the article and info page modules

You can extend or change the article or info page modules in a very similar way.
1
php artisan vendor:publish --tag=hotcoffee_config_articles
2
php artisan vendor:publish --tag=hotcoffee_config_infopages
Copied!
You can create new models, that will extend the ones from the package.
1
<?php
2
3
namespace App\Models;
4
5
class InfoPage extends \TaffoVelikoff\Hotcoffee\InfoPage
6
{
7
//
8
}
Copied!
Now change model in the configuration:
1
<?php
2
3
/*
4
|--------------------------------------------------------------------------
5
| Info Pages
6
|--------------------------------------------------------------------------
7
| Configuration concerning the info pages.
8
|
9
*/
10
11
return [
12
13
/*
14
|--------------------------------------------------------------------------
15
| Models
16
|--------------------------------------------------------------------------
17
| This allows to extend the model.
18
|
19
*/
20
'model' => App\Models\InfoPage::class,
Copied!
Last modified 9mo ago