@if ($post_img)
temporaryUrl() }}">
@endif
Post
Компонент Livewire
namespace App\Livewire\Pages;
// ...Other use namespace calls.
use Livewire\WithFileUploads;
class GroupPage extends Component
{
use WithFileUploads;
public $group_id = '';
public $content = '';
public $post_img;
public function store_post()
{
$validated = $this->validate([
'content' => 'required|string',
'post_img' => 'nullable|image|max:2048', // Add validation rule here
]);
$user_id = Auth::id();
$post = Post::create([
'content' => $validated['content'],
'group_id' => $this->group_id,
'user_id' => $user_id,
]);
if ($this->post_img) {
$filename = $this->post_img->hashName();
$path = $this->post_img->storeAs('uploads/posts');
Asset::create([
'path' => $path,
'type' => 'image',
'user_id' => $user_id,
'post_id' => $post->id(),
]);
}
$this->reset('content');
$this->post_img = null;
session()->flash('success', 'Post created!');
}
// ...
}
Подробнее здесь: https://stackoverflow.com/questions/786 ... e-database
Мобильная версия