当我试图将图像插入数据库中时,它只是向我展示路径,例如http://127.0.0.0.1:8000/storegation/storage/images'
我是Laravel 8的新手,我正在尝试使用图像插入数据,因此,当我尝试插入数据时,它只显示了插入的数据和图像路径。我该如何解决?
file restaurantcontroller.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Restaurant;
class RestaurantController extends Controller
{
function add(Request $request)
{
$resto = new Restaurant;
$resto->name = $request->input('name');
$resto->email = $request->input('email');
$resto->address = $request->input('address');
$resto->create_at = $request->input('create_at');
$resto->uploaded_at = $request->input('uploaded_at');
$resto->image = $request->input('image');
// $resto->image = $request->file('image')->store('images');
if($request->hasFile('image'))
{
$image = $request->file('image');
$image_name = $image->getClientOriginalName();
$image->move(public_path('/images'), $image_name);
$image_path = "/images/" . $image_name;
}
$resto->save();
$request->session()->flash('status', 'Client entered successfully');
return redirect('list');
}
}
file add.blade.blade.php
@extends('layout')
@section('content')
<div class="col-sm-6">
<form method="POST" action="" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" class="form-control" id="name" placeholder="Enter Your Name">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" name="email" class="form-control" id="email"
placeholder="[email protected]">
</div>
<div class="form-group">
<label for="address">Address</label>
<textarea class="form-control" name="address" id="address" rows="3"></textarea>
</div>
<div class="form-group">
<label for="create_at">Create At Date</label>
<input type="date" name="create_at" class="form-control" id="create_at">
</div>
<div class="form-group">
<label for="uploaded_at">Uploaded At Date</label>
<input type="date" name="uploaded_at" class="form-control" id="uploaded_at">
</div>
<div class="form-group">
<label for="image">Image</label>
<input type="file" name="image" class="form-control" id="image">
</div>
<button type="Submit" clas="btn btn-primary">Submit</button>
</form>
</div>
@stop
file web.php
Route::get('/', [RestaurantController::class, 'index']);
Route::view('/add', 'add');
Route::post('/add', [RestaurantController::class, 'add'])->name('add');
i &lt; img src = http://127.0.0.0.1:8000/storeapt Images Alt =“ Image” height =“ 50” width =“ 50”&gt;
,我想要的是 http://127.0.0.0.1:8000/storage/images/`my_image_name`
它告诉我
{“ _ token”:“ exic1hv4sx3qrz6zcqjjjjjnfil6bjblw938hfrkg8j“,“ name”:“ test”,“ email”,“ [email&nbsp; procepted] “ ”,“地址”:“测试地址”,“ create_at”:“ create_at”:“ 2022-05-30”,“ 2022-05-30”,“ “:{}}
作为输出
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以简单地使用
Store()
方法。在刀片模板内部,您可以以这样的方式检索存储的文件:
确保已在公共文件夹中创建了存储文件夹的符号链接。如果没有,可以通过此工匠命令来创建它:
You can simply use the
store()
method.Inside the blade template, you can retrieve the stored file like this:
Make sure you have created the symbolic link of your storage folder in your public folder. If you haven't, you can create it by this artisan command:
您可以使用此代码:
You can use this code: