How grab dynamic start_date & end_date form url to href after i click print?
When i click print, start_date & end_date always null
Here my Views:
<form action="/laporanstok/viewlaporanstok" method="get">
<div >
<div >
<div >
<div >
<label >Tanggal Mulai:</label>
<input type="date" id="start_date" name="start_date"
required>
</div>
</div>
<div >
<div >
<label >Tanggal Akhir:</label>
<input type="date" id="end_date" name="end_date"
required>
</div>
</div>
<div >
<button type="submit" ><i ></i>
Cari</button>
<a href="{{ route('cetak_stok',['start_date'=>"
????",'end_date'=>"????"],) }}" target="_blank" ><i ></i>
Print</a>
<a href="/laporanstok" ><i ></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');
CodePudding user response:
Change this part of your code
<div >
<button type="submit" ><i ></i>
Cari</button>
<a href="{{ route('cetak_stok',['start_date'=>"
????",'end_date'=>"????"],) }}" target="_blank" ><i ></i>
Print</a>
<a href="/laporanstok" ><i ></i>
Reset</a>
</div>
This way you have 2 submit buttons. Submitting form gets those dates you need.
<div >
<button type="submit" name="submit" ><i ></i>
Cari</button>
<button type="submit" name="print" ><i ></i>
Print</button>
<a href="/laporanstok" ><i ></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
}