Я хочу сохранить загруженный файл с оригинальным именем. Например, когда я загружаю web.jpg имя файла в моей папке хранения должно быть web.jpg тоже.
Я уже перепробовал много методов и до сих пор не знаю, как решить эту проблему.
Мой продуктКонтроллер
public function store(Request $request)
{
if($request->hasFile('image'))
{
$file = $request->file('image');
$originalname = $file->getClientOriginalName();
$filename =$originalname;
$file->move('public/', $filename);
}
product::create([
'name' => $request->name,
'id_kategori' => $request->kategori,
'quantity' => $request->quantity,
'price' => $request->price,
'slug' => $request->slug,
'image' => 'public/'. $filename,
]);
return redirect()->route('produk.index');
}
Мой Index.Blade.php
<div class="panel-body">
<table class="table table-striped">
<thead>
<tr>
<th>No</th>
<th>Nama</th>
<th>Kategori</th>
<th>Stok Barang</th>
<th>Harga Barang</th>
<th>Foto</th>
<th>Dibuat Pada</th>
<th>Diedit Pada</th>
<th colspan="8" style="text-align:center;">Aksi</th>
</tr>
</thead>
<tbody>
@foreach ($products as $i => $products)
<tr>
<td>{{ $i+1 }}</td>
<td>{{ $products->name }}</td>
<td>{{ $products->Kategori->name }}</td>
<td>{{ $products->quantity }}</td>
<td>{{ $products->price }}</td>
<td><img src="{{\Illuminate\Support\Facades\Storage::url($products->image)}}"></td>
<td>{{ $products->created_at }}</td>
<td>{{ $products->updated_at }}</td>
<td><a class="btn btn-success" href="{{ route('produk.edit',$products->id) }}"> Edit</a></td>
<td>
<a class="btn btn-info" href="{{ route('show',$products->name) }}"> Lihat</a>
<td>
<form method="post" action="{{ route('produk.destroy',$products->id) }}">
{{ csrf_field() }}
<input type="hidden" name="_method" value="DELETE">
<button class="btn btn-danger" type="submit">Hapus</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>
<a href="{{ route('produk.create') }}" class="btn btn-primary">Tambah Produk</a>
</div>