@fajar it could probably be an issue with your date format and how you are running the queries. Can you show a snippet of the queries you are running/building for the search functionality? that could be helpful.
500 Internal Server error
I want to ask, why am I getting an error 500 internal server error when I search for report data by date
example i am looking for data from date 2022-03-03 to 2022-04-28
i get error 500 internal server error
but when I press the search data button without entering the date there is no error
in my controller
if ($request->has('start_date')) {
$sales = Sale::whereBetween('created_at', [request('start_date'), request('end_date')])
->get();
}
$pdf = PDF::loadView('laporan.pembelian.periode', compact('sales'))->setPaper('a4', 'landscape');
return $pdf->stream('rekap_periode_sales.pdf');
@Fajar when you dd($sales) what do you get?
Also, you may want to cast the created_at column from a timestamp to date when building the query like below.
Sale::whereBetween(DB::raw('DATE(created_at)'), [request('start_date'), request('end_date')])->get();
Why not look in the log file and tell us the actual error?
@Snapey I looked for the file in storage/log/ but there is no file laravel-2022-03-28.log
Looking at your code, what do you think happens if there is no start_date ?
@Snapey when I run it without entering the date
pdf display appears but nothing because there is no date parameter
what do you have as debug setting in your log file?
@Snapey all debug settings are still as before
@Snapey this is the problematic url http://askes.xyz/laporan/periode/pembelian?tgl_awal=2022-03-01&tgl_akhir=2022-03-04
if i run it like this http://askes.xyz/laporan/periode/pembelian?tgl_awal=&tgl_akhir=
not error
@Fajar im asking because you are not seeing the error in the console, and not in the error log
I would temporarily turn on debug
@Snapey i only see error via console in google chrom
@Fajar is this an ajax request?
@Fajar your query params are tgl_awal and tgl_akhir, not start_date and end_date; what does the real Controller code look like?
@tykus sorry, like this
if ($request->has('tgl_awal')) {
$sales = Sale::whereBetween('created_at', [request('tgl_awal'), request('tgl_akhir')])->get();
}
try hard code the date see whether any error.
$from = date('2022-01-01');
$to = date('2022-03-02');
$sales = Sale::whereBetween('created_at', [$from, $to])->get();
@siangboon just the same
@Fajar sanity check....
You have a Model class named Sale in the App\Models namespace; and that model class is imported into the Controller:
use App\Models\Sale;
EDIT looking at the error page - this looks like an older Laravel version, so the correct namespace for the model may be App\Sale
I guess if it result in same error meant most likely your data structure format may got problem... check the date format properly, the table, the model and the input format you pass...
You can only develop on production?
Don't you have a local installation with error debugging enabled?
@Snapey I do not have it
@Fajar you're flying blind without access to the logs and/or a local development environment!
Check the model is correctly namespaced in the Controller as I mentioned above - or inline it, e.g.
\App\Models\Sale::whereBetween(/* etc */)->get()
//or, if appropriate
\App\Sale::whereBetween(/* etc */)->get()
\App\Sale::whereBetween(/* etc */)->get()
setelah saya lakukan migrate:fresh masalah selesai
even it solve your problem but this may not the actual answer for the problem as the "500 -internal server error" error shouldn't related with migration unless you had changed the data format/structure...
@Fajar Use English in the forum so other people can understand you.
Please or to participate in this conversation.