Can you show the game model please ?
Model::create is not storing a file's URL in the database
My database fields looks like this(keep in mind that i'm using a laravel migration as an example):
$table->id();
$table->string('name');
$table->string('genre');
$table->longText('image')->nullable();
$table->timestamps();
When the user store something, i run this command in my controller file(The 'image' field is optional, that's why it is not present in validate():
public function store(Request $request){
$formFields = $request->validate([
'name' => ['required', Rule::unique('game', 'name')],
'genre' => 'required',
'submitGame' => 'required'
]);
//unset($formFields['submitGame']);
//game image
if($request->hasFile('image')){
$image = $request->file('image')->store('gamePoster', 'public');
}
$insert = [
'name' => $formFields['name'],
'genre' => $formFields['genre'],
'image' => $image
];
//storing in database
Game::create($insert);
The image is being uploaded to my folder succesfully, the problem is that somehow the 'image' field does'nt go to the database.
it is really confusing, since the command $image = $request->file('image')->store('gamePoster', 'public'); actually returns a string, i already checked it multiple times. The $image variable(unless the user did not upload any file at all) is never empty.
Check $fillable on the model. Maybe its missing 'image'
Please or to participate in this conversation.