In my Laravel project I render the livewire component for sumit form. But I want to apply the middleware condition for form. Mean if user is not logged in then when he hit the submit button then login page render it can anyone tells me how to solve this problem…
This is my livewire component for form submit
<?php
namespace App\Http\Livewire\Rfq;
use App\Rfq;
use App\City;
use App\currency;
use App\Tbl_units;
use Livewire\Component;
use App\Tbl_productcategory;
use App\Tbl_product_subcategory;
class RfqForm extends Component
{
public $product_name;
public $product_quantity;
public $unit_id;
public $currency_id;
public $purchase_price;
public $city;
public $details;
public $isChecked;
public $product_category_id;
public $subcategories = [];
public $sub_category_id;
public function store()
{
$validatedData = $this->validate([
'product_name' => 'required',
'product_category_id' => 'required',
'sub_category_id' => 'required',
'product_quantity' => 'required',
'unit_id' => 'required|not_in:0',
'purchase_price' => 'required',
'city' => 'required|',
'isChecked' => 'required|accepted',
]);
$validatedData['details'] = $this->details;
auth()->user()->rfqs()->create($validatedData);
session()->flash('message', 'RFQ submitted successfully.');
$this->reset();
}
public function render()
{
if(!empty($this->product_category_id)) {
$this->subcategories = Tbl_product_subcategory::where('procat_id', $this->product_category_id)->get();
}
return view('livewire.rfq.rfq-form')->with([
'categories' => Tbl_productcategory::has('tbl_product_subcategory')->get(),
]);
}
}