Image not showing on table column

Hi, i just trying to create a product crud with image upload inside. The image was uploaded in /storage/public/product, but not showing in my table
Forms\Components\FileUpload::make('foto')
->image()
->directory('product')
->required(),
Forms\Components\FileUpload::make('foto')
->image()
->directory('product')
->required(),
Tables\Columns\ImageColumn::make('foto'),
Tables\Columns\ImageColumn::make('foto'),
$table->string('foto')->nullable();
$table->string('foto')->nullable();
32 Replies
LeandroFerreira
LeandroFerreira4mo ago
did you run php artisan storage:link? did you config APP_URL in the .env? console errors?
sneevilz
sneevilzOP4mo ago
storage:link is already, config APP_URL? mine is https://127.0.0.1:8000 no console error
LeandroFerreira
LeandroFerreira4mo ago
could you show a screenshot?
sneevilz
sneevilzOP4mo ago
No description
No description
No description
No description
No description
LeandroFerreira
LeandroFerreira4mo ago
could you share the code?
sneevilz
sneevilzOP4mo ago
sure
LeandroFerreira
LeandroFerreira4mo ago
add this tooltip
Tables\Columns\ImageColumn::make('foto')
->tooltip(fn (string $state): string => $state)
Tables\Columns\ImageColumn::make('foto')
->tooltip(fn (string $state): string => $state)
what is showing on the tooltip?
sneevilz
sneevilzOP4mo ago
lemme try
sneevilz
sneevilzOP4mo ago
that's give me error
No description
LeandroFerreira
LeandroFerreira4mo ago
there is no state from foto column. Are you sure that is the column name? Any Filament customizations?
sneevilz
sneevilzOP4mo ago
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('barangs', function (Blueprint $table) {
$table->id();
$table->string('foto')->nullable();
$table->string('kode')->unique();
$table->string('nama');
$table->string('kategori');
$table->decimal('harga_beli' ,10,2);
$table->decimal('harga_jual' ,10,2);
$table->integer('stok');
$table->integer('diskon');
$table->string('tipe_barang')->default('default');
$table->string('satuan');
$table->integer('berat');
$table->integer('letak_rak');
$table->string('keterangan')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('barangs');
}
};
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('barangs', function (Blueprint $table) {
$table->id();
$table->string('foto')->nullable();
$table->string('kode')->unique();
$table->string('nama');
$table->string('kategori');
$table->decimal('harga_beli' ,10,2);
$table->decimal('harga_jual' ,10,2);
$table->integer('stok');
$table->integer('diskon');
$table->string('tipe_barang')->default('default');
$table->string('satuan');
$table->integer('berat');
$table->integer('letak_rak');
$table->string('keterangan')->nullable();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('barangs');
}
};
whats wrong?
LeandroFerreira
LeandroFerreira4mo ago
this seems like you don't have foto column in this model/resource 😅 Are you able to share this project on github? could you share Barang model?
sneevilz
sneevilzOP4mo ago
umm model?
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Barang extends Model
{
use HasFactory;

protected $guarded = [
'id',
'foto',
];
}
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Barang extends Model
{
use HasFactory;

protected $guarded = [
'id',
'foto',
];
}
sure
LeandroFerreira
LeandroFerreira4mo ago
Tables\Columns\ImageColumn::make('foto')
->tooltip(fn (Barang $record): string => $record->foto)
Tables\Columns\ImageColumn::make('foto')
->tooltip(fn (Barang $record): string => $record->foto)
what is the tooltip?
sneevilz
sneevilzOP4mo ago
:depressed_tofu:
No description
sneevilz
sneevilzOP4mo ago
how sir..?
sneevilz
sneevilzOP4mo ago
Tables\Columns\ImageColumn::make('foto')
->url(fn($record) => $record->foto ? asset('storage/app/public/product/' . $record->foto) : null)
->tooltip(fn(?string $state): string => $state ?? 'no img'),
Tables\Columns\ImageColumn::make('foto')
->url(fn($record) => $record->foto ? asset('storage/app/public/product/' . $record->foto) : null)
->tooltip(fn(?string $state): string => $state ?? 'no img'),
No description
LeandroFerreira
LeandroFerreira4mo ago
remove foto from guarded in your model
sneevilz
sneevilzOP4mo ago
then..? create a fillable ?
LeandroFerreira
LeandroFerreira4mo ago
app/Models/Barang.php ahh and rename to Barang.php instead of barang.php here
protected $guarded = [
'id',
'foto',//remove
];
protected $guarded = [
'id',
'foto',//remove
];
sneevilz
sneevilzOP4mo ago
already?
No description
sneevilz
sneevilzOP4mo ago
done im also already change the Barang.php class to Barang
LeandroFerreira
LeandroFerreira4mo ago
should work
sneevilz
sneevilzOP4mo ago
lemme try
LeandroFerreira
LeandroFerreira4mo ago
upload the image again
sneevilz
sneevilzOP4mo ago
finnaly
No description
sneevilz
sneevilzOP4mo ago
alright, big thankss! so the problem, is in the models?
LeandroFerreira
LeandroFerreira4mo ago
yep
sneevilz
sneevilzOP4mo ago
thankyou!
LeandroFerreira
LeandroFerreira4mo ago
you can set your repo private now 👍
sneevilz
sneevilzOP4mo ago
It's okay, I did it on purpose 😊 anyway, thank you a lott
Want results from more Discord servers?
Add your server