3

I am using Voyager for a basic BREAD admin to a small web application I am building for a small non-profit. Yearly they need to import 300-500 new semi-complex entries into the database from Excel, so I want to build an admin script that will store all the data in the right places automatically.

Is there a structured way to add a custom controller/view to Voyager?

(I have not found such documentation yet, maybe I am blind. So I have started manually extending existing bits of Voyager, but as I get deeper I want to make sure this is the best option for future growth.)

Dharman
  • 30,962
  • 25
  • 85
  • 135
gokujou
  • 1,482
  • 3
  • 15
  • 27
  • Does this help? https://docs.laravelvoyager.com/customization/overriding-files#using-custom-controllers – Orlando P. Jan 29 '19 at 21:40
  • Probably if I wanted to add an import on all tables in Voyager... Being these imports will touch most all my tables that doesn't feel quite right. I did use this to help see what to extend and how to format it. I didn't want to override existing functionality really though. – gokujou Jan 29 '19 at 21:49
  • Currently I am just mimicking Voyager's admin auth for my custom routes and its view templates, and then extending controllers to fit. I think the biggest issue may be access control if I needed it, but I don't so I may not dig into that. – gokujou Jan 29 '19 at 21:53

2 Answers2

2

Yes, You can add custom controllers to voyager.

First let's make a controller: php artisan make:controller ExportController

//app/Http/Controllers/ExportController.php
class ExportController extends Controller{
   public function form(){
      return view('export.form');
   }
   public function submit(){
      // do export stuff 
   }
}

Add two routes as below:

//routes/web.php
Route::group(['prefix' => 'admin','as' => 'voyager.', 'middleware' => 'admin.user'], function()
{
    Route::get('export','ExportController@form')->name('export.form');
    Route::post('export','ExportController@submit')->name('export.submit');
});

then make the related view file at resources/views/export/form.blade.php just note you need to @extends('voyager::master')

make a new menu item using Voyager's menu builder

Mojtaba Hn
  • 457
  • 2
  • 10
-1

you must use this package. here you can know how to import excel or csv file into database table and export or download in different format using maatwebsite package with the power of PHPOffice's PHPExcel.

and here is video.

  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – atymic Sep 02 '19 at 10:15