My script (a Laravel job) takes the path of an uploaded file (.pdf) and transforms it into a .jpg file name. When the script inserts everything to the database, all fields are added correctly, except the img_name
, which stays null
. When I log the variable in the line above the inserting, it shows up in the logs. I’ve added the column name to the fillable
variable in the model.
Funny thing is, this only happens on production, not on my local machine. The database schema is identical. My knowledge about Laravel is quite limited, as I’m using it only for a couple of weeks.
The job:
$img_name = str_replace('.pdf', '.jpg', explode('/', $this->filePath)[1]);
Log::info('Generated image name: ', ['img_name' => $img_name]);
// Store the extracted text and file information in the database
Log::info('Storing CV in the database for user: ', ['user_id' => $this->user->id]);
$cv = Cv::create([
'user_id' => $this->user->id,
'long_text' => $cv_text,
'file_name' => $this->fileName,
'img_name' => $img_name,
'date_added' => now(),
]);
Log::info('CV stored in the database with ID: ', ['cv_id' => $cv->id]);
The logs:
[2024-09-24 15:29:06] production.INFO: Generated image name: {"img_name":"DM7conE9bnBwV8xg8ETTsojWl0Mk1FgdxfK8alyZ.jpg"}
[2024-09-24 15:29:06] production.INFO: Storing CV in the database for user: {"user_id":10}
[2024-09-24 15:29:06] production.INFO: CV stored in the database with ID: {"cv_id":82}
The model:
protected $fillable = ['user_id', 'long_text', 'file_name', 'img_name', 'date_added'];
- I tried logging the variable, to see if it’s set correctly – It is
- I tried renaming the column and adding a new column to add the
img_name
to – It resulted in the same problem - I tried refreshing the cache – It didn’t work
1