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
LeandroFerreira3mo ago
did you run php artisan storage:link? did you config APP_URL in the .env? console errors?
sneevilz
sneevilzOP3mo ago
storage:link is already, config APP_URL? mine is https://127.0.0.1:8000 no console error
LeandroFerreira
LeandroFerreira3mo ago
could you show a screenshot?
sneevilz
sneevilzOP3mo ago
No description
No description
No description
No description
No description
LeandroFerreira
LeandroFerreira3mo ago
could you share the code?
sneevilz
sneevilzOP3mo ago
sure
LeandroFerreira
LeandroFerreira3mo 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
sneevilzOP3mo ago
lemme try
sneevilz
sneevilzOP3mo ago
that's give me error
No description
LeandroFerreira
LeandroFerreira3mo ago
there is no state from foto column. Are you sure that is the column name? Any Filament customizations?
sneevilz
sneevilzOP3mo 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
LeandroFerreira3mo 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
sneevilzOP3mo 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
LeandroFerreira3mo 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
sneevilzOP3mo ago
:depressed_tofu:
No description
sneevilz
sneevilzOP3mo ago
how sir..?
sneevilz
sneevilzOP3mo 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
LeandroFerreira3mo ago
remove foto from guarded in your model
sneevilz
sneevilzOP3mo ago
then..? create a fillable ?
LeandroFerreira
LeandroFerreira3mo 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
sneevilzOP3mo ago
already?
No description
sneevilz
sneevilzOP3mo ago
done im also already change the Barang.php class to Barang
LeandroFerreira
LeandroFerreira3mo ago
should work
sneevilz
sneevilzOP3mo ago
lemme try
LeandroFerreira
LeandroFerreira3mo ago
upload the image again
sneevilz
sneevilzOP3mo ago
finnaly
No description
sneevilz
sneevilzOP3mo ago
alright, big thankss! so the problem, is in the models?
LeandroFerreira
LeandroFerreira3mo ago
yep
sneevilz
sneevilzOP3mo ago
thankyou!
LeandroFerreira
LeandroFerreira3mo ago
you can set your repo private now 👍
sneevilz
sneevilzOP3mo ago
It's okay, I did it on purpose 😊 anyway, thank you a lott
Want results from more Discord servers?
Add your server