Hello folks.
I'm facing a problem with livewire.
I need to take the files to the public/media/uploads folder, but it's only saving in livewire-tmp. Does anyone have a solution for me to get around this issue? Thanks in advance.
code --->
class CreatePost extends Component
{
use WithFileUploads;
public $title;
public $category = 1;
public $description;
public $image;
protected $rules = [
'image' => 'nullable|image|mimes:jpeg,jpg,png|max:18048',
'title' => 'required|min:4',
'category' => 'required|integer|exists:categories,id',
'description' => 'required|min:4',
];
public function createPost(Request $request)
{
if(auth()->check()){
// IMAGE JPG,PNG,SVG
$randomNumberimg = random_int(1000000000000, 9999999999999);
if ($image = $request->file('image')) {
$destinationPath = 'media/uploads';
$pImage = date('YmdHis') . '_n' . $randomNumberimg. "." . $image->getClientOriginalExtension();
$image->move($destinationPath, $pImage);
$imgpost['image'] = "$pImage";
}
$this->validate([
'image' => 'nullable|image|mimes:jpeg,jpg,png|max:18048',
'title' => 'required|min:4',
'category' => 'required|integer|exists:categories,id',
'description' => 'required|min:4',
]);
Post::create([
'user_id' => auth()->id(),
'category_id' => $this->category,
'status_id' => 1,
'title' => $this->title,
'description' => $this->description,
'image' => $imgpost['image'] ?? '',
]);
session()->flash('success_message', 'Post Adicionado com sucesso');
$this->reset();
return redirect()->route('post.index');
}
abort(Response::HTTP_FORBIDDEN);
}