Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Fajar's avatar
Level 2

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

0 likes
26 replies
deladels's avatar

@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.

Fajar's avatar
Level 2

@deladels

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');
deladels's avatar

@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();
Snapey's avatar

Why not look in the log file and tell us the actual error?

Fajar's avatar
Level 2

@Snapey I looked for the file in storage/log/ but there is no file laravel-2022-03-28.log

Snapey's avatar

Looking at your code, what do you think happens if there is no start_date ?

Fajar's avatar
Level 2

@Snapey when I run it without entering the date

pdf display appears but nothing because there is no date parameter

Snapey's avatar

what do you have as debug setting in your log file?

Snapey's avatar

@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

tykus's avatar

@Fajar your query params are tgl_awal and tgl_akhir, not start_date and end_date; what does the real Controller code look like?

Fajar's avatar
Level 2

@tykus sorry, like this

if ($request->has('tgl_awal')) {
            $sales = Sale::whereBetween('created_at', [request('tgl_awal'), request('tgl_akhir')])->get();
        }
siangboon's avatar

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();
tykus's avatar

@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

siangboon's avatar

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...

Snapey's avatar

You can only develop on production?

Don't you have a local installation with error debugging enabled?

tykus's avatar

@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()
Fajar's avatar
Fajar
OP
Best Answer
Level 2

setelah saya lakukan migrate:fresh masalah selesai

siangboon's avatar

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...

Tray2's avatar

@Fajar Use English in the forum so other people can understand you.

Please or to participate in this conversation.