How to make changes in PanicHD Views files?
Opened this issue · 7 comments
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?
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:
- Open your Laravel app "resources/views/" folder and create a "vendor" subfolder if it does not exist.
- Open this "vendor" subfolder and create subfolder named "panichd", both without any capital letter.
- 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.
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?
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!
-
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". -
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');
});
- 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);
}
}
- 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.
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.
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.
Help me fix this issue please.
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"