Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Call to a member function credit() on null Symfony\Component\Debug\Exception\FatalThrowableError thrown with message "Call to a member function credit() on null" Stacktrace: #0 Symfony\Component\Debug\Exception\FatalThrowableError in /home/eworm.edu.vn/eworm/app/Http/Controllers/TestController.php:43
Application frames (1) All frames (1)
0
Symfony
\
Component
\
Debug
\
Exception
\
FatalThrowableError
/
app
/
Http
/
Controllers
/
TestController.php
43
/
home
/
eworm.edu.vn
/
eworm
/
app
/
Http
/
Controllers
/
TestController.php
//    }
 
    /**
     * Show the test detail.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index(Category $category, Test $test)
    {
        if (!$test->status) {
            return redirect('/home')->with('warning', 'Truy cập bị từ chối.');
        }
 
        $data = json_decode($test->data);
 
        if ($test->type == 'practice' && isset($data->pricing) && $data->pricing) {
            $user = auth()->user();
            // $submits = $user->submits()->get();
            // if (!$submits->isEmpty()) {
                $credit = $user->credit()->first();
 
                $now = new Carbon;
                if (!$credit || $now > $credit->expired_at || $credit->value < 5) {
                    return redirect('/card')->with('warning', 'Tài khoản hết hạn hoặc không đủ số dư. Xin vui lòng nạp hoặc mua thẻ để tiếp tục.');
                } else {
                    $transaction = new Transaction;
 
                    $transaction->value = -5;
                    $transaction->user_id = $user->id;
                    $transaction->type = 'practice access';
                    $transaction->target_id = $test->id;
                    $transaction->save();
 
                    $credit->value -= 5;
                    $credit->save();
                }
            // }
        }
 
        $answers = [];
Arguments
  1. "Call to a member function credit() on null"
    

Environment & details:

empty
empty
empty
empty
empty
Key Value
USER
"nginx"
HOME
"/var/lib/nginx"
HTTP_HOST
"eworm.edu.vn"
HTTP_USER_AGENT
"claudebot"
HTTP_ACCEPT
"*/*"
SCRIPT_FILENAME
"/home/eworm.edu.vn/public_html/index.php"
REDIRECT_STATUS
"200"
SERVER_NAME
"eworm.edu.vn"
SERVER_PORT
"80"
SERVER_ADDR
"128.199.237.213"
REMOTE_PORT
"47694"
REMOTE_ADDR
"52.90.40.84"
SERVER_SOFTWARE
"nginx/1.14.1"
GATEWAY_INTERFACE
"CGI/1.1"
REQUEST_SCHEME
"http"
SERVER_PROTOCOL
"HTTP/1.1"
DOCUMENT_ROOT
"/home/eworm.edu.vn/public_html"
DOCUMENT_URI
"/index.php"
REQUEST_URI
"/test/232"
SCRIPT_NAME
"/index.php"
CONTENT_LENGTH
""
CONTENT_TYPE
""
REQUEST_METHOD
"GET"
QUERY_STRING
""
FCGI_ROLE
"RESPONDER"
PHP_SELF
"/index.php"
REQUEST_TIME_FLOAT
1711646596.0597
REQUEST_TIME
1711646596
APP_NAME
"EWORM"
APP_ENV
"local"
APP_KEY
"base64:funmuWbxogr/26gN+bWquUjFCSnicsJJNOGyaQTQ6YI="
APP_DEBUG
"true"
APP_URL
"http://localhost"
LOG_CHANNEL
"stack"
DB_CONNECTION
"mysql"
DB_HOST
"127.0.0.1"
DB_PORT
"3306"
DB_DATABASE
"eworm"
DB_USERNAME
"eworm"
DB_PASSWORD
"ewormdgds83#*d"
BROADCAST_DRIVER
"log"
CACHE_DRIVER
"file"
QUEUE_CONNECTION
"sync"
SESSION_DRIVER
"file"
SESSION_LIFETIME
"120"
REDIS_HOST
"127.0.0.1"
REDIS_PASSWORD
"null"
REDIS_PORT
"6379"
MAIL_DRIVER
"log"
MAIL_HOST
"smtp.mailtrap.io"
MAIL_PORT
"2525"
MAIL_USERNAME
"null"
MAIL_PASSWORD
"null"
MAIL_ENCRYPTION
"null"
PUSHER_APP_ID
""
PUSHER_APP_KEY
""
PUSHER_APP_SECRET
""
PUSHER_APP_CLUSTER
"mt1"
MIX_PUSHER_APP_KEY
""
MIX_PUSHER_APP_CLUSTER
"mt1"
Key Value
APP_NAME
"EWORM"
APP_ENV
"local"
APP_KEY
"base64:funmuWbxogr/26gN+bWquUjFCSnicsJJNOGyaQTQ6YI="
APP_DEBUG
"true"
APP_URL
"http://localhost"
LOG_CHANNEL
"stack"
DB_CONNECTION
"mysql"
DB_HOST
"127.0.0.1"
DB_PORT
"3306"
DB_DATABASE
"eworm"
DB_USERNAME
"eworm"
DB_PASSWORD
"ewormdgds83#*d"
BROADCAST_DRIVER
"log"
CACHE_DRIVER
"file"
QUEUE_CONNECTION
"sync"
SESSION_DRIVER
"file"
SESSION_LIFETIME
"120"
REDIS_HOST
"127.0.0.1"
REDIS_PASSWORD
"null"
REDIS_PORT
"6379"
MAIL_DRIVER
"log"
MAIL_HOST
"smtp.mailtrap.io"
MAIL_PORT
"2525"
MAIL_USERNAME
"null"
MAIL_PASSWORD
"null"
MAIL_ENCRYPTION
"null"
PUSHER_APP_ID
""
PUSHER_APP_KEY
""
PUSHER_APP_SECRET
""
PUSHER_APP_CLUSTER
"mt1"
MIX_PUSHER_APP_KEY
""
MIX_PUSHER_APP_CLUSTER
"mt1"
0. Whoops\Handler\PrettyPageHandler