Php 不显示Laravel 7标签
我按我的路线做了一个练习 我有一个问题 当我开始创建帖子时,我必须插入一张照片 添加照片时,不会显示该照片 而查看源页面清楚地显示照片已插入,应该显示但不显示 我写了李的密码 CreatePostsRequest Post.php 如果有人能帮我度过一个好的夜晚,我会与之抗争,但我失败了Php 不显示Laravel 7标签,php,laravel,Php,Laravel,我按我的路线做了一个练习 我有一个问题 当我开始创建帖子时,我必须插入一张照片 添加照片时,不会显示该照片 而查看源页面清楚地显示照片已插入,应该显示但不显示 我写了李的密码 CreatePostsRequest Post.php 如果有人能帮我度过一个好的夜晚,我会与之抗争,但我失败了 提前感谢您您没有使用完整的存储路径名,如查看页面源代码所示 首先,您需要确保使用artisan link命令链接存储文件夹和公用文件夹: php artisan存储:链接 接下来,您可以使用存储方法指定公共目录
提前感谢您您没有使用完整的存储路径名,如查看页面源代码所示 首先,您需要确保使用artisan link命令链接存储文件夹和公用文件夹: php artisan存储:链接 接下来,您可以使用存储方法指定公共目录: $image=$request->image->store'public/posts' 现在,您可以通过以下方式访问您的图像:
<img src="{{asset('storage/posts/' . $post->image)}}" alt="">
您没有使用完整的存储路径名,如查看页面源中所示 首先,您需要使用artisan link命令确保存储和公用文件夹链接: php artisan存储:链接 接下来,您可以使用存储方法指定公共目录: $image=$request->image->store'public/posts' 现在,您可以通过以下方式访问您的图像:
<img src="{{asset('storage/posts/' . $post->image)}}" alt="">
你在上传帖子中的图像吗?你检查图像路径是否存在吗?@Hardood Look我添加了文章的其余部分code@ZeroOne看,我添加了代码的其余部分。你在上传帖子时是否也在上传图像?你是否检查图像路径是否存在?@Hardood看,我添加了代码的其余部分code@ZeroOne看,我添加了代码的其余部分,这也是一个很好的实践始终检查图像是否正确存储,然后向数据库插入一行。始终检查图像是否正确存储,然后向数据库插入一行也是一种很好的做法。
<img src="posts/2F2K2uHwvdL11pB8FSmecTeKCCNe1qIaLjCTcOPU.jpeg" alt="">
public function create()
{
return view('posts.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(CreatePostsRequest $request)
{
$image = $request->image->store('posts');
Post::create([
'title' => $request->title,
'description' => $request->description,
'content' => $request->content,
'image' => $image
]);
session()->flash('success','Post is successfully created');
return redirect(route('posts.index'));
}
class CreatePostsRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'title' => 'required|unique:posts',
'description' => 'required',
'image' => 'required|image',
'content' => 'required'
];
}
}
class Post extends Model
{
protected $fillable = [
'title','description','content','image','published_at'
];
}
<img src="{{asset('storage/posts/' . $post->image)}}" alt="">