如何使用Laravel和maatwebsite 3.0中的搜索值从视图中导出数据

时间:2018-05-15 05:29:45

标签: excel laravel phpexcel laravel-5.5 maatwebsite-excel

在我的Laravel项目中,我使用maatwebsite package **(3.0)**从Excel格式的视图中导出数据。

我使用以下代码从视图中导出数据

namespace App\Exports;

use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;

class InvoicesExport implements FromView
{
    public function view(): View
    {
        return view('exports.invoices', [
            'invoices' => Invoice::all()
        ]);
    }
}

如何在此功能中传递搜索输入值并以Excel格式导出数据

1 个答案:

答案 0 :(得分:1)

您只需通过构造函数传递任何值。

05-22 10:51:07.884 22911-22911/eu.domain.app I/EXO PLAYER: isBuffering - true
05-22 10:51:08.180 22911-25217/eu.domain.app I/ACodec:  [] Now uninitialized
05-22 10:51:08.181 22911-25221/eu.domain.app I/ACodec: [] onAllocateComponent
05-22 10:51:08.184 22911-25221/eu.domain.app I/OMXClient: MuxOMX ctor
05-22 10:51:08.210 22911-25221/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] Now Loaded
05-22 10:51:08.214 22911-25220/eu.domain.app I/MediaCodec: [OMX.Exynos.avc.dec] setting surface generation to 23460870
05-22 10:51:08.217 22911-25221/eu.domain.app I/ACodec: can't find wfdsink-exynos-enable
05-22 10:51:08.226 22911-25221/eu.domain.app I/ACodec: codec does not support config priority (err -1010)
05-22 10:51:08.235 22911-25221/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] Now Loaded->Idle
05-22 10:51:08.268 22911-25221/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] configureOutputBuffersFromNativeWindow setBufferCount : 8, minUndequeuedBuffers : 4
05-22 10:51:08.285 22911-25217/eu.domain.app I/ACodec:  [] Now uninitialized
05-22 10:51:08.286 22911-25224/eu.domain.app I/ACodec: [] onAllocateComponent
05-22 10:51:08.299 22911-25221/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] Now Idle->Executing
05-22 10:51:08.303 22911-25224/eu.domain.app I/OMXClient: MuxOMX ctor
05-22 10:51:08.304 22911-25221/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] Now Executing
05-22 10:51:08.323 22911-25224/eu.domain.app I/ACodec: [OMX.google.aac.decoder] Now Loaded
05-22 10:51:08.329 22911-25221/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] Now handling output port settings change
05-22 10:51:08.335 22911-25224/eu.domain.app I/ACodec: codec does not support config priority (err -2147483648)
05-22 10:51:08.337 22911-25221/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] configureOutputBuffersFromNativeWindow setBufferCount : 15, minUndequeuedBuffers : 4
05-22 10:51:08.337 22911-25224/eu.domain.app I/ACodec: [OMX.google.aac.decoder] Now Loaded->Idle
05-22 10:51:08.347 22911-25221/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] Now Executing
05-22 10:51:08.349 22911-25224/eu.domain.app I/ACodec: [OMX.google.aac.decoder] Now Idle->Executing
05-22 10:51:08.350 22911-25224/eu.domain.app I/ACodec: [OMX.google.aac.decoder] Now Executing
05-22 10:51:08.361 22911-25224/eu.domain.app I/ACodec: [OMX.google.aac.decoder] Now handling output port settings change
05-22 10:51:08.398 22911-25224/eu.domain.app I/ACodec: [OMX.google.aac.decoder] Now Executing
05-22 10:51:08.454 22911-25217/eu.domain.app I/AudioTrack: This process already got info. FadeIn[0] FadeOut[0] FadeInRing[0]
05-22 10:51:08.485 22911-22911/eu.domain.app I/EXO PLAYER: isBuffering - false
05-22 10:51:11.898 22911-22922/eu.domain.app I/art: Background sticky concurrent mark sweep GC freed 41338(3MB) AllocSpace objects, 16(388KB) LOS objects, 5% free, 63MB/67MB, paused 4.005ms total 110.586ms
05-22 10:51:13.124 22911-22922/eu.domain.app I/art: Background partial concurrent mark sweep GC freed 15341(1151KB) AllocSpace objects, 2(32KB) LOS objects, 19% free, 65MB/81MB, paused 3.007ms total 105.323ms
05-22 10:51:13.670 22911-22915/eu.domain.app I/art: Do partial code cache collection, code=251KB, data=235KB
05-22 10:51:13.673 22911-22915/eu.domain.app I/art: After code cache collection, code=248KB, data=233KB
    Increasing code cache capacity to 1024KB
05-22 10:51:14.023 22911-23396/eu.domain.app W/ReactNativeJS: Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info.
    (Saw setTimeout with duration 1800000ms)
05-22 10:51:17.806 22911-25220/eu.domain.app I/MediaCodec: [OMX.Exynos.avc.dec] setting surface generation to 23460871
05-22 10:51:17.828 22911-22911/eu.domain.app I/ExoPlayerImpl: Release 2282d90 [ExoPlayerLib/2.8.0] [j5y17lte, SM-J530F, samsung, 24] [goog.exo.core, goog.exo.hls, goog.exo.okhttp]
05-22 10:51:17.829 22911-25221/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] Now Executing->Idle
05-22 10:51:17.852 22911-25221/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] Now Idle->Loaded
    [OMX.Exynos.avc.dec] Now Loaded
     [OMX.Exynos.avc.dec] Now kWhatShutdownCompleted event : 8585
05-22 10:51:17.853 22911-25220/eu.domain.app I/MediaCodec: Codec shutdown complete
05-22 10:51:17.857 22911-25221/eu.domain.app I/ACodec:  [OMX.Exynos.avc.dec] Now uninitialized
     [] Now kWhatShutdownCompleted event : 8585
05-22 10:51:17.858 22911-25220/eu.domain.app I/MediaCodec: Codec shutdown complete
05-22 10:51:17.866 22911-25224/eu.domain.app I/ACodec: [OMX.google.aac.decoder] Now Executing->Idle
05-22 10:51:17.873 22911-25224/eu.domain.app I/ACodec: [OMX.google.aac.decoder] Now Idle->Loaded
    [OMX.google.aac.decoder] Now Loaded
     [OMX.google.aac.decoder] Now kWhatShutdownCompleted event : 8585
05-22 10:51:17.873 22911-25224/eu.domain.app I/MediaCodec: Codec shutdown complete
05-22 10:51:17.878 22911-25224/eu.domain.app I/ACodec:  [OMX.google.aac.decoder] Now uninitialized
     [] Now kWhatShutdownCompleted event : 8585
05-22 10:51:17.878 22911-25224/eu.domain.app I/MediaCodec: Codec shutdown complete
05-22 10:51:17.959 22911-22922/eu.domain.app I/art: Background partial concurrent mark sweep GC freed 10383(476KB) AllocSpace objects, 0(0B) LOS objects, 16% free, 82MB/98MB, paused 9.123ms total 301.557ms
05-22 10:51:19.265 22911-22911/eu.domain.app I/ExoPlayerImpl: Init 3448cf0 [ExoPlayerLib/2.8.0] [j5y17lte, SM-J530F, samsung, 24]
05-22 10:51:19.272 22911-22911/eu.domain.app I/EXO PLAYER: isBuffering - true
05-22 10:51:19.288 22911-22911/eu.domain.app I/EXO PLAYER: isBuffering - true
05-22 10:51:19.410 22911-25298/eu.domain.app I/ACodec:  [] Now uninitialized
05-22 10:51:19.420 22911-25301/eu.domain.app I/ACodec: [] onAllocateComponent
05-22 10:51:19.423 22911-25301/eu.domain.app I/OMXClient: MuxOMX ctor
05-22 10:51:19.449 22911-25301/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] Now Loaded
05-22 10:51:19.458 22911-25300/eu.domain.app I/MediaCodec: [OMX.Exynos.avc.dec] setting surface generation to 23460872
05-22 10:51:19.460 22911-25301/eu.domain.app I/ACodec: can't find wfdsink-exynos-enable
05-22 10:51:19.464 22911-25301/eu.domain.app I/ACodec: codec does not support config priority (err -1010)
05-22 10:51:19.471 22911-25301/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] Now Loaded->Idle
05-22 10:51:19.478 22911-25301/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] configureOutputBuffersFromNativeWindow setBufferCount : 9, minUndequeuedBuffers : 5
05-22 10:51:19.496 22911-25298/eu.domain.app I/ACodec:  [] Now uninitialized
05-22 10:51:19.499 22911-25305/eu.domain.app I/ACodec: [] onAllocateComponent
05-22 10:51:19.501 22911-25305/eu.domain.app I/OMXClient: MuxOMX ctor
05-22 10:51:19.508 22911-25301/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] Now Idle->Executing
05-22 10:51:19.510 22911-25305/eu.domain.app I/ACodec: [OMX.google.aac.decoder] Now Loaded
05-22 10:51:19.510 22911-25301/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] Now Executing
05-22 10:51:19.534 22911-25301/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] Now handling output port settings change
05-22 10:51:19.540 22911-25301/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] configureOutputBuffersFromNativeWindow setBufferCount : 16, minUndequeuedBuffers : 5
05-22 10:51:19.541 22911-25305/eu.domain.app I/ACodec: codec does not support config priority (err -2147483648)
05-22 10:51:19.543 22911-25305/eu.domain.app I/ACodec: [OMX.google.aac.decoder] Now Loaded->Idle
05-22 10:51:19.550 22911-25305/eu.domain.app I/ACodec: [OMX.google.aac.decoder] Now Idle->Executing
05-22 10:51:19.553 22911-25305/eu.domain.app I/ACodec: [OMX.google.aac.decoder] Now Executing
05-22 10:51:19.554 22911-25301/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] Now Executing
05-22 10:51:19.561 22911-25305/eu.domain.app I/ACodec: [OMX.google.aac.decoder] Now handling output port settings change
05-22 10:51:19.572 22911-25305/eu.domain.app I/ACodec: [OMX.google.aac.decoder] Now Executing
05-22 10:51:19.599 22911-25298/eu.domain.app I/AudioTrack: This process already got info. FadeIn[0] FadeOut[0] FadeInRing[0]
05-22 10:51:19.606 22911-22911/eu.domain.app I/EXO PLAYER: isBuffering - false
05-22 10:51:19.634 22911-25300/eu.domain.app I/MediaCodec: [OMX.Exynos.avc.dec] setting surface generation to 23460873
05-22 10:51:24.107 22911-23396/eu.domain.app W/ReactNativeJS: Setting a timer for a long period of time, i.e. multiple minutes, is a performance and correctness issue on Android as it keeps the timer module awake, and timers can only be called when the app is in the foreground. See https://github.com/facebook/react-native/issues/12981 for more info.
    (Saw setTimeout with duration 1800000ms)
05-22 10:51:26.949 22911-25300/eu.domain.app I/MediaCodec: [OMX.Exynos.avc.dec] setting surface generation to 23460874
05-22 10:51:26.967 22911-22911/eu.domain.app I/ExoPlayerImpl: Release 3448cf0 [ExoPlayerLib/2.8.0] [j5y17lte, SM-J530F, samsung, 24] [goog.exo.core, goog.exo.hls, goog.exo.okhttp]
05-22 10:51:26.974 22911-25301/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] Now Executing->Idle
05-22 10:51:26.989 22911-25301/eu.domain.app I/ACodec: [OMX.Exynos.avc.dec] Now Idle->Loaded
    [OMX.Exynos.avc.dec] Now Loaded
     [OMX.Exynos.avc.dec] Now kWhatShutdownCompleted event : 8585
05-22 10:51:26.991 22911-25300/eu.domain.app I/MediaCodec: Codec shutdown complete
05-22 10:51:26.993 22911-25301/eu.domain.app I/ACodec:  [OMX.Exynos.avc.dec] Now uninitialized
05-22 10:51:26.994 22911-25301/eu.domain.app I/ACodec:  [] Now kWhatShutdownCompleted event : 8585
05-22 10:51:26.995 22911-25300/eu.domain.app I/MediaCodec: Codec shutdown complete
05-22 10:51:27.000 22911-25305/eu.domain.app I/ACodec: [OMX.google.aac.decoder] Now Executing->Idle
05-22 10:51:27.010 22911-25305/eu.domain.app I/ACodec: [OMX.google.aac.decoder] Now Idle->Loaded
    [OMX.google.aac.decoder] Now Loaded
     [OMX.google.aac.decoder] Now kWhatShutdownCompleted event : 8585
05-22 10:51:27.010 22911-25305/eu.domain.app I/MediaCodec: Codec shutdown complete
05-22 10:51:27.013 22911-25305/eu.domain.app I/ACodec:  [OMX.google.aac.decoder] Now uninitialized
     [] Now kWhatShutdownCompleted event : 8585
05-22 10:51:27.013 22911-25305/eu.domain.app I/MediaCodec: Codec shutdown complete
05-22 10:51:27.926 22911-22911/eu.domain.app I/ExoPlayerImpl: Init c209446 [ExoPlayerLib/2.8.0] [j5y17lte, SM-J530F, samsung, 24]
05-22 10:51:27.933 22911-22911/eu.domain.app I/EXO PLAYER: isBuffering - true
05-22 10:51:27.953 22911-22911/eu.domain.app I/EXO PLAYER: isBuffering - true

-

return Excel::download(new InvoicesExport(request('q'));    

}

有关传递参数的更多示例,请参阅FromQuery文档:https://laravel-excel.maatwebsite.nl/docs/3.0/export/from-query