Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make changes in PanicHD Views files? #34

Open
ashi006 opened this issue Mar 28, 2021 · 7 comments
Open

How to make changes in PanicHD Views files? #34

ashi006 opened this issue Mar 28, 2021 · 7 comments
Labels
customizations Local app source code improvements to fit your project requirements question Member is looking for information only

Comments

@ashi006
Copy link

ashi006 commented Mar 28, 2021

Hi @xaviqv,

I'm back.. :-)

There is this view file called form.blade.php
vendor/panichd/panichd/src/Views/tickets/createedit/form.blade.php

I want to make changes in this file, I know what I have to change but I don't know how am I supposed to make that change. I have asked this before as well but I'm still confused.

I made changes in the above mentioned file directly in vendor folder and it worked. But I know that it is not the recommended way and I don't want my changes to vanish away on any updates

Can you please please guide me step by step (for once) on how to make changes to this file?

@xaviqv
Copy link
Contributor

xaviqv commented Apr 7, 2021

Hi @ashi006,

One of Laravel cool features is it's view publishing mechanism, that covers exactly what you need. To customize any panichd view you have to:

  1. Open your Laravel app "resources/views/" folder and create a "vendor" subfolder if it does not exist.
  2. Open this "vendor" subfolder and create subfolder named "panichd", both without any capital letter.
  3. Copy "vendor/panichd/panichd/src/Views/tickets/createedit/form.blade.php" to "resources/views/vendor/panichd/tickets/createedit/form.blade.php". Notice that below "resources/views/vendor/panichd/" folder you have to respect the same subfolder structure and filename as it exists in "vendor/panichd/panichd/src/Views"

For any other PanicHD view you want to customize, remember that Laravel will firstly look for it into "resources/views/vendor/panichd" and if it's not found, it will look at "vendor/panichd/panichd/src/Views".

This mechanism may work for majority of other Laravel packages. Cause you mentioned updates, I wanna add that after a PanicHD update, the files in the package folder (vendor/panichd/panichd) may change. After every update you have to review that your customized files (like published views) still work, or you will have to correct them manually.

@xaviqv xaviqv added answered / solved customizations Local app source code improvements to fit your project requirements question Member is looking for information only labels Apr 7, 2021
@ashi006
Copy link
Author

ashi006 commented Apr 25, 2021

Hi @xaviqv
Thanks for your response..
I was able to make it work. Can you please now guide me to update a controller function (same in step by step manner) please?

@xaviqv
Copy link
Contributor

xaviqv commented May 2, 2021

Hi @ashi006,

I'm glad I could help you with views customization.

In your last question I guess you are asking for customizing one of PanicHD controller methods in your app. In this case, Laravel itself doesn't provide an easy method as the view publication method you already know is. Despite that, you may achieve it by at least two different methods: The first one is the "Laravel manner" and the other is "Git manner".

With the "Laravel manner", you keep your own code away from the package under vendor folder. On the other side, with the "Git manner" you will be able to edit any file under "vendor\panichd\panichd" folder without the risk of loosing your code after any app update.

Laravel manner

As an example, let's imagine that you want to customize the "index" method in PanicHD\PanicHD\Controllers\DashboardController, because you want to add extra functionality when you load "http://localhost/panichd/dashboard" in your browser.

To achieve this, we're going to edit two files in our Laravel app:

  • routes\web.php
  • App\Http\Controllers\PanicHD\DashboardController.php

The second one doesn't exist yet and the used folder is arbitrary but recommended for a polite folder structure. You may create it in any other folder within "app" and even use a different filename, but be aware of editing the code example accordingly!

  1. Before editing your app "routes\web.php", you must search into "vendor\panichd\panichd\src\routes.php" the existent route that is using "DashboardController@index". We've found it:
    Route::get("$admin_route_path/dashboard", 'PanicHD\PanicHD\Controllers\DashboardController@index')` ->name("$admin_route.dashboard");
    In this example, let's assume that $admin_route_path value is the default "panichd", so the applied route is "panichd/dashboard" and the route name is "panichd.dashboard".

  2. Edit your app "routes\web.php" and add this:

Route::group(['middleware' => array_merge(
    \PanicHD\PanicHD\Helpers\LaravelVersion::authMiddleware(),
    ['PanicHD\PanicHD\Middleware\IsAdminMiddleware'])], function (){

	Route::get('/panichd/dashboard', 'App\Http\Controllers\PanicHD\DashboardController@index')
	->name('panichd.dashboard');
});
  1. Create "App\Http\Controllers\PanicHD\DashboardController.php" with this content:
<?php

namespace App\Http\Controllers\PanicHD;

use PanicHD\PanicHD\Controllers\DashboardController as original_DashboardController;

class DashboardController extends original_DashboardController
{
    public function index($indicator_period = 2)
    {
		// Your new stuff goes here
		return 'New stuff';
		
		return parent::index($indicator_period);
	}
}
  1. If you open "panichd/dashboard" URL in your browser, you should view our custom message for this route.

Git manner

This method requires to have Git installed on the computer you will be using to edit your Laravel app. It consists in the following ideas:

  • Create a git repository in folder "vendor\panichd\panichd" under your Laravel app
  • Create a "local_dev" branch or similar, where you will work on your customizations
  • When you do any further "composer update", you will be able to control if the package updates affect your own code and adapt it or edit as you require.

My recommendation

Although the Laravel manner works, I'm sure that most Github users around are applying the Git manner, as it keeps the code simpler in a local app and also lets to contribute to the package source code itself.

@ashi006
Copy link
Author

ashi006 commented May 7, 2021

Hi @xaviqv,

Thanks a lot for your detailed response.. Much appreciated.

I have another question.
I've updated "Create New Ticket" form to remove owner dropdown from the form, because my requirement is to create new ticket against logged in user only. As you can see in the image below, there is no dropdown now and the ticket is generating correctly against the logged in user.

image

But the problem is that these tickets are not showing up in the "Active" tab. Attaching the image below, it shows the number of active tickets is 4 but the table shows no data.

image

Help me fix this issue please.

@xaviqv
Copy link
Contributor

xaviqv commented May 14, 2021

Hi @ashi006,

You may custom the create ticket form this way, but if you remove any visual form element, you must add a replacement hidden input within the form HTML tag. For your case it should be:
<input type="hidden" id="owner_id" name="owner_id" value="{{ auth()->user()->id }}">

Notice the id property, which is required also for the "Add comment" script in the same form, and used at file "views\tickets\partials\comments\embedded_scripts.blade.php"

@ashi006
Copy link
Author

ashi006 commented May 18, 2021

Hi @xaviqv,

I did exactly what you told, but no success. It still only updates the count but doesn't show any data in datatable. :-(

@xaviqv
Copy link
Contributor

xaviqv commented May 26, 2021

Hi @ashi006,

Please check your database at panichd_tickets table if there is any new row after you create a new ticket using your custom form.

@xaviqv xaviqv added to confirm solved Waiting for user feedback and removed answered / solved to confirm solved Waiting for user feedback labels May 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customizations Local app source code improvements to fit your project requirements question Member is looking for information only
Projects
None yet
Development

No branches or pull requests

2 participants