Home >Backend Development >PHP Tutorial >How to Redirect URL or Route using Laravel Livewire 3
In this post, I will show How to Redirect URL or Route using Laravel Livewire 3.
In this example, we will create a PhotoUpload Livewire component. This component will feature a form with a file input field and include image validation. The user can select an image, which will then be uploaded to the storage folder using the WithFileUploads trait. After upload image we will redirect route with flash message. You Can Learn How To Session Flash Messages in Laravel Livewire 3
How to Redirect URL or Route using Laravel Livewire 3 Example
Now here we will create a Livewire component using their command. So run the following command to create an add more component.
php artisan make:livewire PhotoUpload
Now they created files on both paths:
app/Livewire/PhotoUpload.php resources/views/livewire/photo-upload.blade.php
Now, both files we will update as below for our contact us form.
app/Livewire/PhotoUpload.php
<?php namespace App\Livewire; use Livewire\Component; use Livewire\WithFileUploads; use App\Models\Image; class PhotoUpload extends Component { use WithFileUploads; public $photo; public function render() { return view('livewire.photo-upload'); } public function submit(){ $this->validate([ "photo" => "required|image" ]); $filepath = $this->photo->store("photos"); $image = Image::create([ "title" => "Test", "filepath" => $filepath ]); session()->flash("success", "Image uploaded successfully"); return redirect()->route("home"); } }
Read More
The above is the detailed content of How to Redirect URL or Route using Laravel Livewire 3. For more information, please follow other related articles on the PHP Chinese website!