| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace App\Http\Livewire;
- use Livewire\Component;
- use Livewire\WithPagination;
- class SegnalazionePervenutaDa extends Component
- {
- use WithPagination;
- protected $paginationTheme = 'bootstrap';
- public $title = 'Segnalazione pervenuta da';
- public $search, $name, $para_agg, $dataId, $update = false, $add = false;
- protected $rules = [
- 'name' => 'required'
- ];
- protected $messages = [
- 'name.required' => 'Il nome è obbligatorio'
- ];
- public function resetFields(){
- $this->name = '';
- $this->para_agg = '';
- }
- public function updatingSearch()
- {
- $this->resetPage();
- }
- public function render()
- {
- $rows = \App\Models\SegnalazionePervenutaDa::where('name', 'like', '%'.$this->search.'%')->orderBy('name')->paginate(10);
- return view('livewire.segnalazione-pervenuta-da', ['records' => $rows]);
- }
- public function add()
- {
- $this->resetFields();
- $this->add = true;
- $this->update = false;
- }
- public function store()
- {
- $this->validate();
- try {
- \App\Models\SegnalazionePervenutaDa::create([
- 'name' => $this->name,
- 'para_agg' => $this->para_agg,
- ]);
- session()->flash('success','Record creato');
- $this->resetFields();
- $this->add = false;
- } catch (\Exception $ex) {
- session()->flash('error','Errore in fase di salvataggio');
- }
- }
- public function edit($id){
- try {
- $record = \App\Models\SegnalazionePervenutaDa::findOrFail($id);
- if( !$record) {
- session()->flash('error','Record non trovato');
- } else {
- $this->name = $record->name;
- $this->para_agg = $record->PARA_AGG;
- $this->dataId = $record->id;
- $this->update = true;
- $this->add = false;
- }
- } catch (\Exception $ex) {
- session()->flash('error','Errore');
- }
- }
- public function update()
- {
- $this->validate();
- try {
- \App\Models\SegnalazionePervenutaDa::whereId($this->dataId)->update([
- 'name' => $this->name,
- 'para_agg' => $this->para_agg,
- ]);
- session()->flash('success','Record aggiornato');
- $this->resetFields();
- $this->update = false;
- } catch (\Exception $ex) {
- session()->flash('success','Errore');
- }
- }
- public function cancel()
- {
- $this->add = false;
- $this->update = false;
- $this->resetFields();
- }
- public function delete($id)
- {
- try{
- \App\Models\SegnalazionePervenutaDa::find($id)->delete();
- session()->flash('success',"Record eliminato");
- }catch(\Exception $e){
- session()->flash('error',"Errore");
- }
- }
- }
|