0

Создаю пост в блоге. Часть кода из контроллера PostController

public function store(CreatePostRequest $request)
    {
        
       $image = ($request->image->store('posts'));
      
        Post::create([
            'title' => $request->title,
            'description' => $request->description,
            'content' => $request->content,
            'image' => $request->image         
        ]);
       

        session()->flash('success','Пост успішно сворений');
        
        return redirect(route('posts.index'));

    }

Потом в файле index.blade.php беру и делаю вывод

@foreach($posts as $post)
				
{{$post->image}}
            
@endforeach

Проблемма в том что изображение выводится вот так

W:\userdata\temp\php6A4A.tmp

А мне нужен вид

posts/gfdgfdgdgd.jpeg

кто знает как решить проблемму.
Laravel 5.8

1 ответ 1

0

Проблемма решилась когда я поправил две строки кода

public function store(CreatePostRequest $request)
    {
        
       $image = $request->image->store('posts'); - тут убрал скобки
      
        Post::create([
            'title' => $request->title,
            'description' => $request->description,
            'content' => $request->content,
            'image' => $image    - тут картинка       
        ]);
       

        session()->flash('success','Пост успішно сворений');
        
        return redirect(route('posts.index'));

    }

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.