-1

How grab dynamic start_date & end_date form url to href after i click print?

enter image description here

When i click print, start_date & end_date always null

enter image description here

Here my Views:

<form action="/laporanstok/viewlaporanstok" method="get">
                            <div class="container align-items-center">
                                <div class="row">
                                    <div class="col-6">
                                        <div class="form-group">
                                            <label class="font-weight-bold">Tanggal Mulai:</label>
                                            <input type="date" id="start_date" name="start_date" class="form-control"
                                                required>
                                        </div>
                                    </div>
                                    <div class="col-6">
                                        <div class="form-group">
                                            <label class="font-weight-bold">Tanggal Akhir:</label>
                                            <input type="date" id="end_date" name="end_date" class="form-control"
                                                required>
                                        </div>
                                    </div>
                                    <div class="container text-center">
                                        <button type="submit" class="btn btn-success"><i class="fas fa-search"></i>
                                            Cari</button>
                                        <a href="{{ route('cetak_stok',['start_date'=>"
                                            ????",'end_date'=>"????"],) }}" target="_blank" class="btn
                                            btn-primary"><i class="fas fa-print"></i>
                                            Print</a>
                                        <a href="/laporanstok" class="btn btn-danger"><i class="fas fa-sync-alt"></i>
                                            Reset</a>
                                    </div>
                                </div>
                            </div>
                        </form>

My Models:

class M_Laporan_Stok extends Model
{
    use HasFactory;

    protected $table = 'tbl_barang';
    protected $primaryKey = 'id_barang';
    protected $fillable = [
        'id_proyek',
        'kode_barang',
        'nama_barang',
        'tipe_barang',
        'stok',
        'created_at',
        'updated_at'
    ];
}

My Controller:

public function print(Request $request)
    {
        $data = [
            'title' => 'Cetak Stok',
            'judul' => 'Halaman Cetak Stok',
            'start_date' => $request->start_date,
            'end_date' => $request->end_date,
        ];

               return view('/content/laporan_stok/v_cetak_laporan_stok', $data);
    }

My Route:

Route::get('/laporanstok/cetak', [LaporanStokController::class, 'print'])->name('cetak_stok');

1 Answers1

0

Change this part of your code

<div class="container text-center">
                                    <button type="submit" class="btn btn-success"><i class="fas fa-search"></i>
                                        Cari</button>
                                    <a href="{{ route('cetak_stok',['start_date'=>"
                                        ????",'end_date'=>"????"],) }}" target="_blank" class="btn
                                        btn-primary"><i class="fas fa-print"></i>
                                        Print</a>
                                    <a href="/laporanstok" class="btn btn-danger"><i class="fas fa-sync-alt"></i>
                                        Reset</a>
</div>

This way you have 2 submit buttons. Submitting form gets those dates you need.

<div class="container text-center">
                                    <button type="submit" name="submit" class="btn btn-success"><i class="fas fa-search"></i>
                                        Cari</button>
                                     <button type="submit" name="print" class="btn btn-primary"><i class="fas fa-print"></i>
                                        Print</button>
                                    <a href="/laporanstok" class="btn btn-danger"><i class="fas fa-sync-alt"></i>
                                        Reset</a>
</div>

In controller check what button was clicked.

if (isset($_POST['submit'])) {
   //submit button was clicked
} else if (isset($_POST['print'])) {
   //print button was clicked
} else {
   //no button pressed
}
zivkovicf
  • 57
  • 1
  • 6
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 21 '21 at 10:21