i'm developing an application with laravel 8 and livewire.
I've created in the view gestionale.blade.php three component (table) with the following operation.
The first table is populated when the page is loaded, then a row is selected and the second table is populated with a click event, finally by clicking a row in the second table the third table is populated.
From the Livewire documentation I used the events, but I only have the correct functioning of the first one, that is, clicking on the first table populates the second, but then clicking a row on the second I get nothing.
I entered a dump & die inside the code and I just don't get to raise the event in the second table.
This is my code:
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Illuminate\Http\Request;
use App\Models\MinutaArticolo;
use Livewire\WithPagination;
use Illuminate\Support\Facades\DB;
use App\Tenant;
class TableArticoliContent extends Component
{
//Dichiariamo il listener degli eventi
protected $listeners = ['getArticoli' => 'getArticoli'];
protected $connection = null;
public $articoli = null;
protected $paginationTheme = 'bootstrap';
public function mount(Request $request) {
if(null !== $request->get('throughMiddleware'))
$this->connection = 'tenant';
else
$this->connection = null;
}
// Funzione richiamata dal componente livewire e che ritorna gli articoli
// a seconda dell'id partita passato
public function getArticoli($id_partita) {
if(null !== request()->get('throughMiddleware'))
$this->connection = 'tenant';
else
$this->connection = null;
$this->articoli = MinutaArticolo::on($this->connection)->where('id_minuta_partita', '=', $id_partita)->paginate(15)->toArray();
}
public function render()
{
return view('livewire.table-articoli-content')
->with('articoli', $this->articoli);
}
}
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Illuminate\Http\Request;
use App\Models\MinutaArticolo;
use Livewire\WithPagination;
use Illuminate\Support\Facades\DB;
use App\Tenant;
class TableArticoli extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
public function render() {
return view('livewire.table-articoli');
}
}
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Livewire\WithPagination;
use Illuminate\Http\Request;
use App\Models\AnagraficaSoggetto;
class TablePraticheContent extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
protected $connection = null;
public $pratiche = null;
protected $listeners = ['filtri' => 'renderWithFilter'];
public function mount(Request $request) {
// Setto la connessione
if(null !== $request->get('throughMiddleware'))
$this->connection = 'tenant';
else
$this->connection = null;
// Recupero i dati da renderizzare
$anagrafica = new AnagraficaSoggetto();
$anagrafica->setConnection($this->connection);
$this->pratiche = $anagrafica->select(
'denominazioneSoggetto',
'anagrafica_soggetto.codiceFiscale',
'indirizzoPOSTA',
'tipologia_imposta.descrizione_sintetica',
'importoCarico as carico',
'importoResiduo as residuo',
'pagatoNormale as riscosso',
'pagatoDiscarico as sgravio',
'data_assegnazione',
'username as collaboratore',
'minuta_partita.id',
'minuta_partita.id_minuta as id_minuta',
'partita_pagamenti.progressivoRiscossione',
'partita_pagamenti.agenteRiscossione'
)->distinct()
->join('minuta_partita', 'minuta_partita.id_soggetto', '=', 'anagrafica_soggetto.id')
->join('users', 'minuta_partita.id_user', '=', 'users.id', 'left outer')
->join('partita_pagamenti', 'partita_pagamenti.id_minuta_partita', '=', 'minuta_partita.id', 'left outer')
->join('tipologia_imposta', 'minuta_partita.id_tipologia_imposta', '=', 'tipologia_imposta.id')
->paginate(15)->toArray();
}
//funzione per triggerare l'evento onclick sulla tabella pratiche
public function clickPartiteTrigger($id) {
$this->emit('getPartite', $id);
$this->render = false;
}
public function render() {
return view('livewire.table-pratiche-content')
->with('pratiche', $this->pratiche);
}
public function renderWithFilter($filtered){
$this->pratiche = $filtered;
}
}
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Livewire\WithPagination;
use Illuminate\Http\Request;
use App\Models\AnagraficaSoggetto;
class TablePratiche extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
public function render() {
return view('livewire.table-pratiche');
}
}
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\MinutaPartita;
use Livewire\WithPagination;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Tenant;
class TablePartiteContent extends Component
{
//Dichiariamo il listener degli eventi
protected $listeners = ['getPartite' => 'getPartite',
'filtri_partite' => 'renderWithFilter'];
protected $connection = null;
public $partite = null;
protected $paginationTheme = 'bootstrap';
public function mount(Request $request) {
if(null !== $request->get('throughMiddleware'))
$this->connection = 'tenant';
else
$this->connection = null;
}
//funzione per triggerare l'evento onclick sulla tabella partite
public function clickArticoliTrigger($id) {
dd($id);
$this->emit('getArticoli', $id);
$this->render = false;
}
// Funzione richiamata dal componente livewire e che ritorna le partite
// a seconda dell'id pratica passato
public function getPartite($id_minuta) {
if(null !== request()->get('throughMiddleware'))
$this->connection = 'tenant';
else
$this->connection = null;
$this->partite = MinutaPartita::on($this->connection)->where('id_minuta', '=', $id_minuta)->paginate(15)->toArray();
}
public function render() {
return view('livewire.table-partite-content')
->with('partite', $this->partite);
}
public function renderWithFilter($filtered){
$this->partite = $filtered;
}
}
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\MinutaPartita;
use Livewire\WithPagination;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Tenant;
class TablePartite extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
public function render() {
return view('livewire.table-partite');
}
}
and this is my component in which i've the event which must make me populate the third table
<tbody id="partite_result">
#if (!empty($partite))
#foreach ($partite['data'] as $pt)
<tr wire:click="clickArticoliTrigger({{ $pt['id']}})">
<td>{{ $pt['annoRuolo'] }}</td>
<td>{{ $pt['numeroRuolo'] }}</td>
<td>{{ $pt['agenteRiscossione'] ?? ''}}</td>
<td>{{ $pt['annoRif'] ?? '' }}</td>
<td>{{ $pt['tipoImposta'] ?? '' }}</td>
<td>{{ $pt['id_minuta_partita'] ?? '' }}</td>
<td>{{ $pt['importoCarico'] }}</td>
<td>{{ $pt['pagatoNormale'] }}</td>
<td>{{ $pt['pagatoDiscarico'] }}</td>
<td>{{ $pt['importoResiduo'] }}</td>
<td>{{ $pt['proceduraEsecutiva'] }}</td>
<td>{{ $pt['importoInesigibilita'] }}</td>
<td>{{ $pt['stato'] ?? ''}}</td>
</tr>
#endforeach
#endif
</tbody>
Can someone have any tips or advice to help me? Thanks to all :-)
EDIT (this is my component code):
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Partite</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table id="example5" class="display" style="min-width: 845px">
<thead>
<tr>
<th>Anno ruolo</th>
<th>Numero ruolo</th>
<th>Agente Riscossione</th>
<th>Anno imposta</th>
<th>Tipo imposta</th>
<th>Partita</th>
<th>Carico</th>
<th>Riscosso</th>
<th>Sgravio</th>
<th>Residuo</th>
<th>Peocedura</th>
<th>Inesigibile</th>
<th>Stato</th>
</tr>
</thead>
<livewire:table-partite-content />
<livewire:tbl-partite-footer-filter />
</table>
</div>
</div>
</div>
</div>
</div>
Clearer code:
I've this route: Route::get('/gestionale', [App\Http\Controllers\GestionaleController::class, 'index']);
And i go in the view blade called gestionale.blade.php and in this view i've my three livewire component.
The code of the view gestionale.blade.php is:
{{-- Extends layout --}}
#extends('layout.layout2')
{{-- Content --}}
#section('content')
<div class="container-fluid">
<div class="row page-titles mx-0">
<div class="col-sm-6 p-md-0">
<div class="welcome-text">
<h4>Benvenuto sul Gestionale</h4>
<span>Qui sono listate pratche, partite e articoli</span>
</div>
</div>
</div>
<!-- import del componente gestionale header filter per i filtri -->
<livewire:gestionale-header-filter>
<!-- fine import del componente gestionale header filter -->
<hr/>
<!-- import dei component livewire (tab: partite, pratiche, articoli) -->
<livewire:table-pratiche /> // first component (event on this works)
<hr/>
<livewire:table-partite /> // second component (in this, the event not works)
<hr/>
<livewire:table-articoli /> // third component
<!-- fine dell'import dei component livewire (tab: partite, pratiche, articoli) -->
<div class="row">
<div class="col-xl-12">
<div class="card">
<div class="card-body">
<!-- button per l'apertura dei modal -->
<div class="btn-group">
<button type="button" class="btn btn-primary mb-2" data-toggle="modal" data-target="#PagamentoLongModal">Aggiungi pagamento</button>
<button type="button" class="btn btn-primary mb-2" data-toggle="modal" data-target=".bd-example-modal-lg">Aggiungi assegnatario</button>
<button type="button" class="btn btn-primary mb-2" data-toggle="modal" data-target="#ShowPagamentiModal">Pagamenti</button>
<button type="button" class="btn btn-primary mb-2" data-toggle="modal" data-target="#ProcedureInesigibilitaModal">Procedure/Inesigibilità</button>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Inizio dei modal per gestire le azioni del gestionale -->
<!-- modal per l'inserimento di un pagamento -->
<div class="modal fade" id="PagamentoLongModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Aggungi un pagamento</h5>
<button type="button" class="close" data-dismiss="modal"><span>×</span>
</button>
</div>
<div class="modal-body">
<!-- da aggiungere l'azione -->
<div class="basic-form">
<form method="POST" action="#">
#csrf
<div class="form-group row">
<label class="col-sm-3 col-form-label">Ente</label>
<div class="col-sm-9">
<input type="text" class="form-control input-rounded" placeholder="Ente" value="" disabled>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Partita</label>
<div class="col-sm-9">
<input type="text" class="form-control input-rounded" placeholder="Partita" disabled>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Anno Rif.</label>
<div class="col-sm-9">
<input type="text" class="form-control input-rounded" placeholder="Anno Riferimento" disabled>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Anno</label>
<div class="col-sm-9">
<input type="text" class="form-control input-rounded" placeholder="Anno" disabled>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Numero</label>
<div class="col-sm-9">
<input type="text" class="form-control input-rounded" placeholder="Numero" disabled>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Carico</label>
<div class="col-sm-9">
<input type="number" class="form-control input-rounded" placeholder="Carico" disabled>
</div>
</div>
<hr/>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Tipologia</label>
<div class="col-sm-9">
<input type="text" class="form-control input-rounded" placeholder="Tipologia">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Imposta</label>
<div class="col-sm-9">
<input type="number" class="form-control input-rounded" placeholder="Imposta">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Decimali</label>
<div class="col-sm-9">
<input type="number" class="form-control input-rounded" placeholder="Decimali imposta" maxlenght="2">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Mora</label>
<div class="col-sm-9">
<input type="number" class="form-control input-rounded" placeholder="Mora">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Decimali</label>
<div class="col-sm-9">
<input type="number" class="form-control input-rounded" placeholder="Decimali mora" maxlength="2">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Data Pagamento</label>
<div class="col-sm-9">
<input type="date" class="form-control input-rounded" placeholder="Email">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Data Registrazione</label>
<div class="col-sm-9">
<input type="date" class="form-control input-rounded" placeholder="Email">
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">Note</label>
<div class="col-sm-9">
<input type="text" class="form-control input-rounded" placeholder="Email" minlength="3" maxlength="255">
</div>
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger light" data-dismiss="modal">Chiudi</button>
<button type="button" class="btn btn-primary">Salva</button>
</div>
</div>
</div>
</div>
<!-- modal per l'inserimento di un assegnatario -->
<div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Aggiungi un assegnatario</h5>
<button type="button" class="close" data-dismiss="modal"><span>×</span>
</button>
</div>
<div class="modal-body">
<!-- da aggiungere l'azione -->
<form method="POST" action="#">
<div class="form-group row">
<div class="form-group">
<label>Seleziona assegnatari (tieni premuto shift per una selezione multipla):</label>
<select multiple class="form-control input-rounded" id="sel2">
#if(!empty($users))
#foreach($users as $u)
<option value="{{$u->id}}">{{$u->username}}</option>
#endforeach
#endif
</select>
</div>
<div class="form-group">
<label class="col-sm-12 col-form-label">Data Assegnazione</label>
<div class="col-sm-12">
<input type="date" class="form-control input-rounded" placeholder="Data Assegn.">
</div>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger light" data-dismiss="modal">Chiudi</button>
<button type="button" class="btn btn-primary">Salva</button>
</div>
</div>
</div>
</div>
<!-- modal per visualizzare i pagamenti associati alla partita -->
<div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true" id="ShowPagamentiModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Pagamenti associati alla partita</h5>
<button type="button" class="close" data-dismiss="modal"><span>×</span>
</button>
</div>
<div class="modal-body">
<!-- da aggiungere il corpo del body -->
<p>Body da aggiungere, da capire i dati da mostrare a video</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger light" data-dismiss="modal">Chiudi</button>
<button type="button" class="btn btn-primary"><i class="fa fa-print" aria-hidden="true"></i> Stampa</button>
</div>
</div>
</div>
</div>
<!-- modal per visualizzare le procedure e le inesigibilita associati alla partita -->
<div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true" id="ProcedureInesigibilitaModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Procedure e Inesigibilità</h5>
<button type="button" class="close" data-dismiss="modal"><span>×</span>
</button>
</div>
<div class="modal-body">
<!-- da aggiungere il corpo del body -->
<p>Body da aggiungere, da capire i dati da mostrare a video</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger light" data-dismiss="modal">Chiudi</button>
<button type="button" class="btn btn-primary"><i class="fa fa-print" aria-hidden="true"></i> Stampa</button>
</div>
</div>
</div>
</div>
<!-- fine dei modal per gestire le azioni del gestionale -->
<!-- IMPORTANTE: AGGIUNGERE IL CSRF TOKEN PRIMA DI ANDARE IN PRODUZIONE -->
#endsection
For table-pratiche i've this structure of my livewire component
table-pratiche:
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Pratiche</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table id="example4" class="display" style="min-width: 845px">
<thead>
<tr>
<th>Soggetto</th>
<th>Codice Fiscale</th>
<th>Indirizzo</th>
<th>Tipo di imposta</th>
<th>Carico</th>
<th>Riscosso</th>
<th>Sgravio</th>
<th>Residuo</th>
<th>Assegnatario</th>
<th>Data assegn.</th>
<th>Dettagli</th>
</tr>
</thead>
<livewire:table-pratiche-content />
<livewire:tbl-pratiche-footer-filter />
</table>
</div>
</div>
</div>
</div>
</div>
table-pratiche-content:
<tbody id="filter_result">
#if (!empty($pratiche))
<?php
$carico = 0;
$riscosso = 0;
$sgravio = 0;
$residuo = 0;
?>
#foreach ($pratiche['data'] as $p)
<tr wire:click="clickPartiteTrigger({{ $p['id_minuta'] }})">
<td>{{ $p['denominazioneSoggetto'] }}</td>
<td>{{ $p['codiceFiscale'] }}</td>
<td>{{ $p['indirizzoPOSTA'] }}</td>
<td>{{ $p['descrizione_sintetica'] }}</td>
<td>{{ $p['carico'] }}</td>
<td>{{ $p['riscosso'] }}</td>
<td>{{ $p['sgravio'] }}</td>
<td>{{ $p['residuo'] }}</td>
<td>Collaboratore</td>
<td>{{ $p['data_assegnazione'] }}</td>
<td><span class="badge light badge-warning">Pending</span></td>
<?php
$carico = $carico + $p['carico'];
$riscosso = $riscosso + $p['riscosso'];
$sgravio = $sgravio + $p['sgravio'];
$residuo = $residuo + $p['residuo'];
?>
</tr>
#endforeach
#endif
</tbody>
For table-partite in the same way i've:
table-partite:
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Partite</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table id="example5" class="display" style="min-width: 845px">
<thead>
<tr>
<th>Anno ruolo</th>
<th>Numero ruolo</th>
<th>Agente Riscossione</th>
<th>Anno imposta</th>
<th>Tipo imposta</th>
<th>Partita</th>
<th>Carico</th>
<th>Riscosso</th>
<th>Sgravio</th>
<th>Residuo</th>
<th>Peocedura</th>
<th>Inesigibile</th>
<th>Stato</th>
</tr>
</thead>
<livewire:table-partite-content />
<livewire:tbl-partite-footer-filter />
</table>
</div>
</div>
</div>
</div>
</div>
table-partite-content
<tbody id="partite_result">
#if (!empty($partite))
#foreach ($partite['data'] as $pt)
<tr wire:click="clickArticoliTrigger({{ $pt['id']}})">
<td>{{ $pt['annoRuolo'] }}</td>
<td>{{ $pt['numeroRuolo'] }}</td>
<td>{{ $pt['agenteRiscossione'] ?? ''}}</td>
<td>{{ $pt['annoRif'] ?? '' }}</td>
<td>{{ $pt['tipoImposta'] ?? '' }}</td>
<td>{{ $pt['id_minuta_partita'] ?? '' }}</td>
<td>{{ $pt['importoCarico'] }}</td>
<td>{{ $pt['pagatoNormale'] }}</td>
<td>{{ $pt['pagatoDiscarico'] }}</td>
<td>{{ $pt['importoResiduo'] }}</td>
<td>{{ $pt['proceduraEsecutiva'] }}</td>
<td>{{ $pt['importoInesigibilita'] }}</td>
<td>{{ $pt['stato'] ?? ''}}</td>
</tr>
#endforeach
#endif
</tbody>
and in the last, for table-articoli i've
table-articoli
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Articoli</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table id="example4" class="display" style="min-width: 845px">
<thead>
<tr>
<th>Codice Tributo</th>
<th>Descrizione</th>
<th>Progressivo</th>
<th>Carico</th>
<th>Dettaglio utenza</th>
</tr>
</thead>
<livewire:table-articoli-content />
</table>
</div>
</div>
</div>
</div>
</div>
-table-articoli-content
<tbody id="articoli_result">
#if (!empty($articoli))
#foreach ($articoli as $a)
<tr>
<td>{{ $a->codiceEntrata }}</td>
<td>{{ $a->descrizioneArticolo }}</td>
<td>{{ $a->progressivoArticolo}}</td>
<td>{{ $a->importoCarico }}</td>
<td>{{ $a->descrizioneArticolo}}</td>
</tr>
#endforeach
#endif
</tbody>
The livewire components are the component posted in the previous question
Related
I'm using Laravel 9 and trying to use CRUD with my model Project which has the following DB table.
When I try to edit a project using the button "edit" on this view:
"projets.index":
#extends('header')
#section('content')
<div class="col-sm-8" style="background: rgba(204, 204, 204,0.5);padding:5%;width:100%">
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2 style="text-align: center">Les projets</h2>
</div>
<div class="pull-right">
<a class="btn btn-success" href="{{ route('projets.create') }}"> Créée un nouveau projet</a>
</div>
</div>
</div>
#if ($message = Session::get('success'))
<div class="alert alert-success">
<p>{{ $message }}</p>
</div>
#endif
<table class="table table-bordered">
<tr>
<th>id du projet</th>
<th>description</th>
<th width="280px">Action</th>
</tr>
#foreach ($projects as $project)
<tr>
<td>{{ $project->id_project }}</td>
<td>{{ $project->description }}</td>
<td>
<form action="{{ route('projets.destroy',$project->id_project) }}" method="Post">
<a class="btn btn-primary" href="{{ route('galleries.index',$project->id_project,'id_project') }}">ajouter</a>
<a class="btn btn-primary" href="{{ route('projets.edit',[$project->id_project]) }}">Edit</a>
#csrf
#method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
#endforeach
</table>
{!! $projects->links() !!}
</div>
#endsection
I have the following error:
"Missing required parameter for [Route: projets.update] [URI: projets/{projet}] [Missing parameter: projet]."
"projets.edit":
#extends('header')
#section('content')
<div class="row">
<div class="col-lg-12 margin-tb">
<div class="pull-left">
<h2>Edit projet</h2>
</div>
<div class="pull-right">
<a class="btn btn-primary" href="{{ route('projets.index') }}"> Back</a>
</div>
</div>
</div>
#if ($errors->any())
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form action="{{ route('projets.update',$project->id_project) }}" method="POST" enctype="multipart/form-data">
#csrf
#method('PUT')
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<strong>Company Address:</strong>
<input type="text" name="address" value="{{ $project->description }}" class="form-control" placeholder="Company Address">
#error('address')
<div class="alert alert-danger mt-1 mb-1">{{ $message }}</div>
#enderror
</div>
</div>
<button type="submit" class="btn btn-primary ml-3">Submit</button>
</div>
</form>
#endsection
Update function inside the controller (ProjectController):
public function update(Request $request, $id_project)
{
$request->validate([
'description' => 'required',
]);
User::create($request->all());
$project->description = $request->description;
$project->save();
return redirect()->route('projets.index')
->with('success','project Has Been updated successfully');
}
public function edit(Project $project)
{
return view('projets.edit',compact('project'));
}
Project model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Project extends Model
{
protected $fillable = [
'id_project', 'description'
];
}
Sorry if my questions seems strange English is not my first language
This is my livewire component class code
This is my livewire component class code
This is my livewire component class code This is my livewire component class code
<?php
namespace App\Http\Livewire;
use Livewire\WithPagination;
use Livewire\Component;
use App\Models\student;
class Students extends Component
{
public $selectData= true;
public $createtData= false;
public $updateData= false;
public $name;
public $email;
public $country;
public $studentID;
public $edi_name;
public $edi_email;
public $edi_country;
public $total_student;
use WithPagination;
public function render()
{ $this->total_student=student::get();
$student=student::orderBy('studentID','ASC')->paginate(100);
return view('livewire.students',['student'=>$student])->extends('layouts.app');
}
public function showform()
{
dd('kawish');
$this->selectData=false;
$this->createtData=true;
}
public function resetField()
{
$this->$name="";
$this->$email="";
$this->$country="";
$this->studentID;
$this->edi_name="";
$this->edi_email="";
$this->edi_country="";
}
public function create()
{
$student=new student();
$this->validate([
'name'=>'required',
'email'=>'required',
'country'=>'required',
]);
//This is my livewire
$student->name=$this->name;
$student->email=$this->email;
$student->country=$this->country;
$result =$student->save();
$this->resetField();
$this->selectData=true;
$this->createtData=false;
}
public function edit($studentID)
{
$this->selectData=false;
$this->updateData=true;
$student= student::findorFail($studentID);
$this->studentID=$student->studentID;
$this->edi_name=$student->name;
$this->edi_email=$student->email;
$this->edi_country=$student->country;
}
public function update($studentID)
{
$student= student::findorFail($studentID);
$this->validate([
'edi_name'=>'required',
'edi_email'=>'required',
'edi_country'=>'required',
]);
$student->name=$this->edi_name;
$student->email=$this->edi_email;
$student->country=$this->edi_country;
$result =$student->save();
$this->resetField();
$this->selectData=true;
$this->updateData=false;
}
public function delete($studentID){
$student= student::findorFail($studentID);
$result=$student->delete();
}
}
//This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire //This is my livewire
This is my view for the same class
This is my view for the same classT his is my view for the same class
<div>
#section('title','students')
#section('content')
<div class=" container">
<div class="mt-5">
<div class=" card">
<div class=" card-header">
<div class=" d-flex justify-content-between">
<h3>users ({{count($total_student)}})</h3>
<div>
<button wire:click='showform' class="btn btn-success">Add User</button> *//error
</div>
</div>
</div>
</div>
</div>
List item
{{-- table list --}}
#if ($selectData==true)
<div class=" table-responsive mt-5">
<table class="table table-bordered">
<thead>
<tr class="bg-dark text-light">
<th>ID</th>
<th>Name</th>
<th>Email</th>
<th>Country</th>
<th>Options</th>
</tr>
</thead>
#forelse ( $student as $item )
<tbody>
<tr>
<td>{{ $item->studentID }}</td>
<td>{{ $item->name }}</td>
<td>{{ $item->email }}</td>
<td>{{ $item->country }}</td>
<td>
<button class="btn btn-success" wire:click="edit({{$item->studentID }})">Edit</button>
<button class="btn btn-danger" wire:click="delete({{$item->studentID }})">Delete</button>
</td>
</tr>
#empty
<tr>
<td>
<p class="text-danger">#record not found</p>
</td>
</tr>
</tbody>
#endforelse
</table>
</div>
#endif
{{-- create data --}}
#if ($createtData==true)
<div class="row">
<div class=" col-xl-6 col-md-8 col-sm-12 offset-xl-3 offset-md-2 offset-sm-0">
<div class="card">
<div class="card-header">
<h1>Add Data</h1>
</div>
<form action="" class="mt-5" wire.submit.prevent='create'>
<div class="card-body">
<div class=" form-group">
<label for="name">Enter Name</label>
<input wire:model='name' type="text" name="name" id="name" class="form-control form-control-lg">
<span class="text-danger">
#error('name')
{{ $message }}
#enderror
</span>
</div>
<div class=" form-group">
<label for="email">Enter Email</label>
<input wire:model='email' type="email" name="email" id="email" class="form-control form-control-lg">
#error('email')
{{ $message }}
#enderror
</div>
<div class=" form-group">
<label for="country">Enter Country</label>
<input wire:model='country' type="text" name="country" id="country" class="form-control form-control-lg">
#error('country')
{{ $message }}
#enderror
</div>
</div>
<div class=" card-footer">
<button class="btn btn-success">Save</button>
</div>
</form>
</div>
</div>
</div>
#endif
{{-- update data --}}
#if ($updateData==true)
<div class="row mt-5">
<div class=" col-xl-6 col-md-8 col-sm-12 offset-xl-3 offset-md-2 offset-sm-0">
<div class="card">
<div class="card-header">
<h1>Update Data</h1>
</div>
<form action="" class="mt-5" wire.submit.prevent='update({{$studentID}})'>
<div class="card-body">
<div class=" form-group">
<label for="name">Enter Name</label>
<input wire:model="edi_name" type="text" name="name" id="name" class="form-control form-control-lg">
<span class="text-danger">
#error('edi_name')
{{ $message }}
#enderror
</span>
</div>
<div class=" form-group">
<label for="email">Enter Email</label>
<input wire:model="edi_email" type="email" name="email" id="email" class="form-control form-control-lg">
<span class="text-danger">
#error('edi_email')
{{ $message }}
#enderror
</span>
</div>
<div class=" form-group">
<label for="country">Enter Country</label>
<input wire:model="edi_name" type="text" name="country" id="country" class="form-control form-control-lg">
<span class="text-danger">
#error('edi_country')
{{ $message }}
#enderror
</span>
</div>
</div>
<div class=" card-footer">
<button class="btn btn-success">Update</button>
</div>
</form>
</div>
</div>
</div>
#endif
</div>
#endsection
//This is my livewire //This is my livewire
my layout codes
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>#yield('title')</title>
<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
#livewireStyles
</head>
<body>
<div class="container-fluid bg-dark">
<div class=" container p-4">
<h2 class="text-center text-white">Laravel Livewire Crud</h2>
</div>
</div>
<div>
#yield('content')
</div>
#livewireScripts
</body>
</html>
`**my routing**`
<?php
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Route;
use Inertia\Inertia;
use App\Http\Livewire\Students;
// Route::view('/', 'app');
Route::get('/', Students::class);
here its endsssss
here its endsssss
Remove the #section in your component view. livewire component needs to start with a . You can extend your section inside the component to have it like this
public function render()
{ $this->total_student=student::get();
$student=student::orderBy('studentID','ASC')->paginate(100);
return view('livewire.students',['student'=>$student])->extends('layouts.app')->slot('content");
}
You can have your component view like this
<div class=" container">
<div class="mt-5">
<div class=" card">
<div class=" card-header">
<div class=" d-flex justify-content-between">
<h3>users ({{count($total_student)}})</h3>
<div>
<button wire:click='showform' class="btn btn-success">Add User</button> *//error
</div>
</div>
</div>
</div>
</div>
i have created the admin panel where im saving every data, the main thing is the user want to add or edit data from admin panel for his site. its like a blog.
first i have done the slider section where im fetching data from admin panel to client site.
this is the slider section code which is working perfectly.
Add file
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="">ARABIC SECTION</h1>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<hr>
<div class="col-md-12 float-left">
<div class="card">
<div class="card-header">
<h3 class="card-title text-lg float-left col-md-12" >
Manage Home Section
<a class="float-right btn btn-danger" href="{{ URL('/admin/post/list')}}">Back</a>
</h3>
</div>
<!-- /.card-header -->
<div class="card-body">
<div class="tab-content p-0">
<form action="{{ url('/arabicpost/submit')}}" method="POST" enctype="multipart/form-data">
#csrf
<div class="card-body">
<div class="form-group">
<label for="">Title 1</label>
<input type="text" name="title" class="form-control" id="exampleInputTitle" placeholder="Enter Title 1">
#error('title')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Description 1</label>
<textarea class="form-control" name="description" id="" cols="30" rows="10" placeholder="Description 1"></textarea>
#error('description')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="exampleInputFile">File input 1</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="image" class="custom-file-input" id="exampleInputFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
<div class="input-group-append">
<span class="input-group-text">Upload</span>
</div>
</div>
#error('image')
<span>{{ $message }}</span>
#enderror
</div>
</div>
<div class="card-header">
<h3 class="card-title text-lg float-left col-md-12">
Second Banner
</h3>
</div>
<div class="card-body">
<div class="form-group">
<label for="">Title 2</label>
<input type="text" name="title2" class="form-control" id="exampleInputTitle" placeholder="Enter Title 2">
#error('title2')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Description 2</label>
<textarea class="form-control" name="description2" id="" cols="30" rows="10" placeholder="Description 2"></textarea>
#error('description2')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="exampleInputFile">File input 2</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="image2" class="custom-file-input" id="exampleInputFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
<div class="input-group-append">
<span class="input-group-text">Upload</span>
</div>
</div>
#error('image2')
<span>{{ $message }}</span>
#enderror
</div>
</div>
<div class="card-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div><!-- /.card-body -->
</div></div></div></div>
#endsection
List File
#extends('admin.layouts.app')
#section('main-content')
<div class="content-wrapper">
<div class="card" style="margin-top:5%">
<div class="card-header">
<h2 class="text-center">English Home Section</h2>
<div class="col-sm-12" style="text-align: center; color:green; font-size:20px">{{session('msg')}}</div>
<div class="col-sm-12" style="text-align: center; color:red; font-size:20px">{{session('msgForDelete')}}</div>
</div>
<div class="card-header">
<a class="btn btn-success" href="{{ URL('/admin/post/add')}}">Add Post</a>
</div>
<!-- /.card-header -->
<div class="card-body">
<table id="example1" class="table table-bordered table-striped table-responsive">
<thead>
<tr width="100%">
<th width="3%">ID</th>
<th width="10%">Title 1</th>
<th width="23.5%">Description 1</th>
<th width="10%">Title 2</th>
<th width="23.5%">Description 2</th>
<th width="10%">Image 1</th>
<th width="10%">Image 2</th>
<th width="10%">Action</th>
</tr>
</thead>
<tbody>
<?php
// echo '<pre>';
// print_r([$result]);
// die();
?>
#foreach ($result as $list)
<tr>
<td>{{$list->id}}</td>
<td>{{$list->title}}</td>
<td>{{$list->description}}</td>
<td>{{$list->title2}}</td>
<td>{{$list->description2}}</td>
<td><img src="{{ asset('storage/app/public/post/'.$list->image) }}" width="150px"/></td> <td><img src="{{ asset('storage/app/public/post/secondbanner/'.$list->image2) }}" width="150px"/></td>
<td><a class="btn btn-primary" href="{{('/haffiz/admin/post/edit/'.$list->id)}}">Edit</a>
<a class="btn btn-danger" href="{{('/haffiz/admin/post/delete/'.$list->id)}}">Delete</a>
</td>
</tr>
#endforeach
</tbody>
<tfoot>
<tr>
<th>ID</th>
<th>Title 1</th>
<th>Description 1</th>
<th>Title 2</th>
<th>Description 2</th>
<th>Image 1</th>
<th>Image 2</th>
<th>Action</th>
</tr>
</tfoot>
</table>
</div></div></div> </div>
#endsection
edit file
#extends('admin.layouts.app')
#section('main-content')
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="">ENGLISH SECTION</h1>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<hr>
<div class="col-md-12 float-left">
<div class="card">
<div class="card-header">
<h3 class="card-title text-lg float-left col-md-12" >
Manage Home Section
<a class="float-right btn btn-danger" href="{{ URL('/admin/post/list')}}">Back</a>
</h3>
</div>
<!-- /.card-header -->
<div class="card-body">
<div class="tab-content p-0">
<form action="{{ url('/admin/post/update/'.$result['0']->id)}}" method="POST" enctype="multipart/form-data">
#csrf
<div class="card-body">
<div class="form-group">
<label for="">Title</label>
<input type="text" name="title" class="form-control" id="exampleInputTitle" value="{{$result['0']->title}}" placeholder="Enter Title">
#error('title')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Description</label>
<textarea class="form-control" name="description" id="" cols="30" rows="10" placeholder="Description">{{$result['0']->description}} </textarea>
#error('description')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="image" class="custom-file-input" id="exampleInputFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
<div class="input-group-append">
<span class="input-group-text">Upload</span>
</div>
</div>
#error('image')
<span>{{ $message }}</span>
#enderror
</div>
</div>
<!-- /.card-body -->
<div class="card-body">
<div class="form-group">
<label for="">Title 2</label>
<input type="text" name="title2" class="form-control" id="exampleInputTitle" value="{{$result['0']->title2}}" placeholder="Enter Title">
#error('title2')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Description 2</label>
<textarea class="form-control" name="description2" id="" cols="30" rows="10" placeholder="Description">{{$result['0']->description2}} </textarea>
#error('description2')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="exampleInputFile">File input 2</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="image2" class="custom-file-input" id="exampleInputFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
<div class="input-group-append">
<span class="input-group-text">Upload</span>
</div>
</div>
#error('image2')
<span>{{ $message }}</span>
#enderror
</div>
</div>
<!-- /.card-body -->
<div class="card-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div><!-- /.card-body -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="">ENGLISH SECTION</h1>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<hr>
<div class="col-md-12 float-left">
<div class="card">
<div class="card-header">
<h3 class="card-title text-lg float-left col-md-12" >
Manage Home Section
<a class="float-right btn btn-danger" href="{{ URL('/admin/post/list')}}">Back</a>
</h3>
</div>
</div>
</div>
</div>
</div>
#endsection
its Controller(Post)
<?php
namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class Post extends Controller
{
function listing()
{
$data['result'] = DB::table('posts')->orderBy('id','desc')->get();
return view('admin.post.list',$data);
}
function submit(Request $req)
{
//validation
$req->validate([
'title' => 'required',
'description' => 'required',
'title2' => 'required',
'description2' => 'required',
'image' => 'mimes: jpg,jpeg,png',
'image2' => 'mimes: jpg,jpeg,png'
]);
//storing image
$image=$req->file('image');
$ext = $image->extension();
$file=time().'.'.$ext;
$image->storeAs('public/post',$file);
$image2=$req->file('image2');
$ext2 = $image2->extension();
$file2=time().'.'.$ext2;
$image2->storeAs('public/post/secondbanner',$file2);
//array
$data = array(
'title' => $req->input('title'),
'description' => $req->input('description'),
'title2' => $req->input('title2'),
'description2' => $req->input('description2'),
'image' => $file,
'image2' => $file2,
);
//inserting data
DB::table('posts')->insert($data);
$req->session()->flash('msg','Data has been Added');
return redirect('/admin/post/list');
}
function delete(Request $req , $id)
{
DB::table('posts')->where('id',$id)->delete();
$req->session()->flash('msgForDelete','Data has been Deleted');
return redirect('/admin/post/list');
}
function edit(Request $req , $id)
{
$data['result'] = DB::table('posts')->where('id',$id)->get();
return view('admin.post.edit',$data);
}
function update(Request $req , $id)
{
//validation
$req->validate([
'title' => 'required',
'description' => 'required',
'title2' => 'required',
'description2' => 'required',
'image' => 'mimes: jpg,jpeg,png',
'image2' => 'mimes: jpg,jpeg,png'
]);
//array
$data = array(
'title' => $req->input('title'),
'description' => $req->input('description'),
'title2' => $req->input('title2'),
'description2' => $req->input('description2'),
);
if($req->hasfile('image'))
{
$image=$req->file('image');
$ext = $image->extension();
$file=time().'.'.$ext;
$file2=time().'.'.$ext;
$image->storeAs('public/post/',$file,$file2);
$data['image']=$file;
}
if($req->hasfile('image2'))
{
$image2=$req->file('image2');
$ext = $image2->extension();
$file2=time().'.'.$ext;
$image2->storeAs('public/post/secondbanner',$file2);
$data['image2']=$file2;
}
//updating data
DB::table('posts')->where('id',$id)->update($data);
$req->session()->flash('msg','Data has been Updated');
return redirect('/admin/post/list');
}
}
and this is a controller where im sending data to client site.
<?php
namespace App\Http\Controllers\user;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
class EngHafizController extends Controller
{
public function login()
{
return view('user.english.login');
}
public function registration()
{
return view('user.english.registration');
}
public function homefront()
{
return view('user.english.index');
}
public function home()
{
$data['result'] = DB::table('posts')->get();
return view('user.english.index',$data);
}
public function about()
{
$data['aboutresult'] = DB::table('abouts')->get();
return view('user.english.about',$data);
}
public function whyhaffez()
{
return view('user.english.whyhaffez');
}
public function oursheikh()
{
return view('user.english.oursheikh');
}
public function contact()
{
return view('user.english.contact');
}
}
This is all working properly.
lets get to the point. when try to do the same for ABOUT section
it give me the error which is
(Undefined variable: aboutresult (View:C:\xampp\htdocs\haffiz\resources\views\user\english\index.blade.php))
i do the same thing for about section
<?php
namespace App\Http\Controllers\admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class AboutController extends Controller
{
function about_listing()
{
$data['aboutresult'] = DB::table('abouts')->orderBy('id','desc')->get();
return view('admin.post.about.aboutlist',$data);
}
function about_submit(Request $request)
{
//validation
$request->validate([
'title3' => 'required',
'heading3' => 'required',
'description3' => 'required',
'image3' => 'mimes: jpg,jpeg,png'
]);
//storing image
$image3=$request->file('image3');
$ext = $image3->extension();
$file=time().'.'.$ext;
$image3->storeAs('public/post/about_image',$file);
//array
$data = array(
'title3' => $request->input('title3'),
'heading3' => $request->input('heading3'),
'description3' => $request->input('description3'),
'image3' => $file,
);
//inserting data
DB::table('abouts')->insert($data);
$request->session()->flash('msg','Data has been Added');
return redirect('/admin/post/about/aboutlist');
}
function about_delete(Request $request , $id)
{
DB::table('abouts')->where('id',$id)->delete();
$request->session()->flash('msgForDelete','Data has been Deleted');
return redirect('/admin/post/list');
}
function about_edit(Request $request , $id)
{
$data['aboutresult'] = DB::table('abouts')->where('id',$id)->get();
return view('admin.post.about.aboutedit',$data);
}
function about_update(Request $request , $id)
{
//validation
$request->validate([
'title3' => 'required',
'heading3' => 'required',
'description3' => 'required',
'image3' => 'mimes: jpg,jpeg,png'
]);
//array
$data = array(
'title3' => $request->input('title3'),
'heading3' => $request->input('heading3'),
'description3' => $request->input('description3'),
);
if($request->hasfile('image3'))
{
$image3=$request->file('image3');
$ext = $image3->extension();
$file=time().'.'.$ext;
$image3->storeAs('public/post/about_image',$file);
$data['image3']=$file;
}
//updating data
DB::table('abouts')->where('id',$id)->update($data);
$request->session()->flash('msg','Data has been Updated');
return redirect('/admin/post/about/aboutlist');
}
}
aboutLIST
#extends('admin.layouts.app')
#section('main-content')
<div class="content-wrapper">
<div class="card">
<div class="card-header">
<h2 >About Section</h2>
<div class="col-sm-12" style="text-align: center; color:green; font-size:20px">{{session('msg')}}</div>
<div class="col-sm-12" style="text-align: center; color:red; font-size:20px">{{session('msgForDelete')}}</div>
</div>
<div class="card-header">
<a class="btn btn-success" href="{{ URL('/admin/post/about/about')}}">Add Post</a>
</div>
<!-- /.card-header -->
<div class="card-body">
<table id="example1" class="table table-bordered table-striped">
<thead>
<tr width="100%">
<th width="">ID</th>
<th width="10">Title </th>
<th width="40">Heading</th>
<th width="15">Description </th>
<th width="10">Image </th>
<th width="25%">Action</th>
</tr>
</thead>
<tbody>
<?php
// echo '<pre>';
// print_r([$aboutresult]);
// die();
?>
#foreach ($aboutresult as $aboutlist)
<tr>
<td>{{$aboutlist->id}}</td>
<td>{{$aboutlist->title3}}</td>
<td>{{$aboutlist->heading3}}</td>
<td>{{$aboutlist->description3}}</td>
<td><img src="{{ asset('storage/app/public/post/about_image/'.$aboutlist->image3) }}" width="150px" height="100px"/></td>
<td>
<a class="btn btn-primary" href="{{('/haffiz/admin/post/about/aboutedit/'.$aboutlist->id)}}">Edit</a>
<a class="btn btn-danger" href="{{('/haffiz/admin/post/delete'.$aboutlist->id)}}" >Delete</a>
</td>
</tr>
#endforeach
</tbody>
<tfoot>
<tr>
<th width="4">ID</th>
<th width="10">Title </th>
<th width="40">Heading</th>
<th width="15">Description </th>
<th width="10">Image</th>
<th width="25%">Action</th>
</tr>
</tfoot>
</table>
</div>
<!-- /.card-body -->
</div>
</div>
</div>
#endsection
aboutedit
#extends('admin.layouts.app')
#section('main-content')
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<section class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="">ENGLISH SECTION</h1>
</div>
</div>
</div><!-- /.container-fluid -->
</section>
<hr>
<div class="col-md-12 float-left">
<div class="card">
<div class="card-header">
<h3 class="card-title text-lg float-left col-md-12" >
Edit About Section
<a class="float-right btn btn-danger" href="{{ URL('/admin/post/about/aboutlist')}}">Back</a>
</h3>
</div>
<!-- /.card-header -->
<div class="card-body">
<div class="tab-content p-0">
<form action="{{ url('/admin/post/about/update/'.$aboutresult['0']->id)}}" method="POST" enctype="multipart/form-data">
#csrf
<div class="card-body">
<div class="form-group">
<label for="">Title</label>
<input type="text" name="title3" class="form-control" id="exampleInputTitle" value="{{$aboutresult['0']->title3}}" placeholder="Enter Title">
#error('title3')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Heading</label>
<input class="form-control" name="heading3" id="" placeholder="Heading" value="{{$aboutresult['0']->heading3}}">
#error('heading3')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="">Description </label>
<textarea class="form-control" name="description3" id="" cols="30" rows="10" placeholder="Description ">{{$aboutresult['0']->description3}}</textarea>
#error('description3')
<span>{{ $message }}</span>
#enderror
</div>
<div class="form-group">
<label for="exampleInputFile">File input</label>
<div class="input-group">
<div class="custom-file">
<input type="file" name="image3" class="custom-file-input" id="exampleInputFile">
<label class="custom-file-label" for="exampleInputFile">Choose file</label>
</div>
<div class="input-group-append">
<span class="input-group-text">Upload</span>
</div>
</div>
#error('image3')
<span>{{ $message }}</span>
#enderror
</div>
</div>
<!-- /.card-body -->
<div class="card-footer">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</form>
</div>
</div><!-- /.card-body -->
</div>
</div>
</div>
</div>
#endsection
this the index file where im fetching
#foreach ($result as $list)
<img src="{{ asset('storage/app/public/post/'.$list->image) }}" class="d-block w-100" alt="...">
<div class="col-12 text-left">
<h1 class="animated slideInDown">{{ $list->title }}</h1>
<svg class="animated slideInDown" width="128" height="9" viewBox="0 0 128 9" fill="none" xmlns="http://www.w3.org/2000/svg">
</svg>
<p class="animated slideInLeft">{{ $list->description }}</p>
Read More
</div>
<div class="carousel-item">
<img src="{{ asset('storage/app/public/post/secondbanner/'.$list->image2) }}" class="d-block w-100" alt="...">
<h1 class="animated slideInDown">{{ $list->title2}}</h1>
<p class="animated slideInLeft">{{ $list->description2 }}</p>
#endforeach
</div>
about section
#foreach($aboutresult as $aboutlist)
<div class="col-xl-7 about-p">
<h5 class="about-welcome">{{$aboutlist->title3}}</h5>
#endforeach
public function home()
{
$data['aboutresult'] = DB::table('abouts')->get();
$data['result'] = DB::table('posts')->get();
return view('user.english.index',$data);
}
I am developing a multi-tenant web app with laravel 8 and livewire and I have a problem with filters and pagination.
The application is a management software through which the user displays report data in tables (created as livewire components), which are paginated and from which he can obtain filtered data.
Examples of filters are anno, procedura, etc ...
When filters are applied to the tables, they return the data correctly filtered and paginated, but if the page is changed, the filters are not kept and therefore all the rows are shown again.
Anyone have any advice or ideas? I can't understand what is causing this problem ... thanks everyone for the help :-)
here my code:
TablePratiche
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Livewire\WithPagination;
use Illuminate\Http\Request;
use App\Models\AnagraficaSoggetto;
class TablePratiche extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
public function render()
{
return view('livewire.table-pratiche');
}
}
-TablePraticheContent
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Livewire\WithPagination;
use Illuminate\Http\Request;
use App\Models\AnagraficaSoggetto;
class TablePraticheContent extends Component
{
use WithPagination;
protected $paginationTheme = 'bootstrap';
protected $connection = null;
public $pratiche = null;
protected $listeners = ['filtri' => 'renderWithFilter'];
public function mount(Request $request)
{
// Setto la connessione
if (null !== $request->get('throughMiddleware')) {
$this->connection = 'tenant';
} else {
$this->connection = null;
}
// Recupero i dati da renderizzare
$anagrafica = new AnagraficaSoggetto();
$anagrafica->setConnection($this->connection);
$this->pratiche = $anagrafica->select(
'denominazioneSoggetto',
'anagrafica_soggetto.codiceFiscale',
'indirizzoPOSTA',
'tipologia_imposta.descrizione_sintetica',
'importoCarico as carico',
'importoResiduo as residuo',
'pagatoNormale as riscosso',
'pagatoDiscarico as sgravio',
'data_assegnazione',
'username as collaboratore',
'minuta_partita.id',
'minuta_partita.id_minuta as id_minuta',
'partita_pagamenti.progressivoRiscossione',
'partita_pagamenti.agenteRiscossione',
)->distinct()
->join('minuta_partita', 'minuta_partita.id_soggetto', '=', 'anagrafica_soggetto.id')
->join('users', 'minuta_partita.id_user', '=', 'users.id', 'left outer')
->join('partita_pagamenti', 'partita_pagamenti.id_minuta_partita', '=', 'minuta_partita.id', 'left outer')
->join('tipologia_imposta', 'minuta_partita.id_tipologia_imposta', '=', 'tipologia_imposta.id')
->paginate(15)
->toArray();
//dd($this->pratiche);
}
//funzione per triggerare l'evento onclick sulla tabella pratiche
public function clickPartiteTrigger($id)
{
$this->emit('getPartite', $id);
// questo evento passa al gestionale-modal-component l'id della pratica
//in questo modo possiamo prenderlo per l'apertura del modal
$this->emit('getPratica', $id);
}
public function render()
{
return
view('livewire.table-pratiche-content')
->with('pratiche', $this->pratiche);
}
public function renderWithFilter($filtered)
{
$this->pratiche = $filtered;
//dd($this->pratiche);
}
}
-GestionaleHeaderFilter
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use Illuminate\Http\Request;
use App\Models\MinutaPartita;
use App\Models\AnagraficaSoggetto;
use App\Models\TipologiaImposta;
use Illuminate\Support\Facades\DB;
use Livewire\WithPagination;
use App\Tenant;
class GestionaleHeaderFilter extends Component
{
protected $paginationTheme = 'bootstrap';
protected $connection = null;
public $first_render = true;
public $filtered = null;
public $nomi_imposta = null;
public $anni_riferimento = null;
// Definiamo l'array dei filtri (anno, tipo imposta, procedure, inesigibilita, residui)
public $filter = [
'anno' => '', // filtro per anno
'procedura' => '', // filtro per procedura
'inesigibilita' => '', // filtro per inesigibilita
'imposta' => '', // filtro per tipo imposta
'residui' => '' // filtro per residui
];
public function mount(Request $request)
{
if (null !== $request->get('throughMiddleware')) {
$this->connection = 'tenant';
} else {
$this->connection = null;
}
$this->nomi_imposta = TipologiaImposta::on($this->connection)
->select('id', 'descrizione_sintetica', 'descrizione_imposta')
->orderBy('descrizione_imposta', 'ASC')
->get()
->toArray();
$this->anni_riferimento = MinutaPartita::on($this->connection)
->select('annoRiferimento')
->distinct()
->orderByDesc('annoRiferimento')
->get()
->toArray();
}
public function filtri()
{
if (null !== request()->get('throughMiddleware')) {
$this->connection = 'tenant';
} else {
$this->connection = null;
}
$options = array();
// Recupero le le condizioni di where
if ($this->filter['anno'] != '') {
$options['minuta_partita.annoRiferimento'] = $this->filter['anno'];
}
if ($this->filter['imposta'] != '') {
$options['tipologia_imposta.id'] = $this->filter['imposta'];
}
if ($this->filter['procedura'] != '') {
$options['proceduraEsecutiva'] = $this->filter['procedura'];
}
if ($this->filter['inesigibilita'] != '') {
$options['inesigibilita'] = $this->filter['inesigibilita'];
}
$anagrafica = new AnagraficaSoggetto();
$anagrafica->setConnection($this->connection);
$pratiche = $anagrafica->select(
'denominazioneSoggetto',
'anagrafica_soggetto.codiceFiscale',
'indirizzoPOSTA',
'tipologia_imposta.descrizione_sintetica',
'importoCarico as carico',
'importoResiduo as residuo',
'pagatoNormale as riscosso',
'pagatoDiscarico as sgravio',
'data_assegnazione',
'username as collaboratore',
'id_minuta_partita',
'minuta_partita.id_minuta as id_minuta',
'partita_pagamenti.progressivoRiscossione',
'partita_pagamenti.agenteRiscossione',
)->distinct()
->join('minuta_partita', 'minuta_partita.id_soggetto', '=', 'anagrafica_soggetto.id')
->join('partita_pagamenti', 'partita_pagamenti.id_minuta_partita', '=', 'minuta_partita.id', 'left outer')
->join('users', 'minuta_partita.id_user', '=', 'users.id', 'left outer')
->join('tipologia_imposta', 'minuta_partita.id_tipologia_imposta', '=', 'tipologia_imposta.id');
foreach ($options as $key => $value) {
$pratiche = $pratiche->where($key, '=', $value);
}
if ($this->filter['residui'] != '') {
$pratiche = $pratiche->where('importoResiduo', '>', '0');
}
$this->filtered = $pratiche->paginate(15)->toArray();
$this->emit('filtri', $this->filtered);
}
public function render()
{
return view('livewire.gestionale-header-filter')
->with('nomi_imposta', $this->nomi_imposta)
->with('anni', $this->anni_riferimento);
//->with('idt', $idt);
}
}
Hi I open this question to post the blade code of my views.
gestionale.blade.php
{{-- Extends layout --}}
#extends('layout.layout2')
{{-- Content --}}
#section('content')
#if ($errors->any())
<div class="card-body">
<div class="alert alert-danger alert-dismissible fade show solid alert-rounded">
<button type="button" class="close h-100" data-dismiss="alert" aria-label="Close"><span><i
class="mdi mdi-close"></i></span>
</button>
<ul>
#foreach ($errors->all() as $error)
<li>{{ ucfirst($error) }}</li>
#endforeach
</ul>
</div>
</div>
#endif
#if (!empty(session()->get('error')))
<div class="card-body">
<div class="alert alert-danger alert-dismissible fade show solid alert-rounded">
<button type="button" class="close h-100" data-dismiss="alert" aria-label="Close"><span><i
class="mdi mdi-close"></i></span>
</button>
<strong>Error!! </strong>{{ session()->get('error') }}
</div>
</div>
#endif
#if (!empty(session()->get('results')))
<div class="card-body">
#foreach (session()->get('results') as $result)
#if(isset($result['error']))
<div class="alert alert-danger alert-dismissible fade show solid alert-rounded">
<button type="button" class="close h-100" data-dismiss="alert" aria-label="Close"><span><i
class="mdi mdi-close"></i></span>
</button>
<ul>
<li>{{ ucfirst($result['error']) }}</li>
</ul>
</div>
#else
<div class="alert alert-success alert-dismissible fade show solid alert-rounded">
<button type="button" class="close h-100" data-dismiss="alert" aria-label="Close"><span><i
class="mdi mdi-close"></i></span>
</button>
<ul>
<li>{{ ucfirst($result['success']) }}</li>
</ul>
</div>
#endif
#endforeach
</div>
#endif
#if (!empty(session()->get('success')))
<div class="card-body">
<div class="alert alert-success alert-dismissible fade show solid alert-rounded">
<button type="button" class="close h-100" data-dismiss="alert" aria-label="Close"><span><i
class="mdi mdi-close"></i></span>
</button>
<strong>Success!! </strong>{{ session()->get('success') }}
</div>
</div>
#endif
<div class="container-fluid">
<div class="row page-titles mx-0">
<div class="col-sm-6 p-md-0">
<div class="welcome-text">
<h4>Sei sul gestionale di {{ $idt }}</h4>
<span>Qui sono listate pratche, partite e articoli</span>
</div>
</div>
</div>
<!-- import del componente gestionale header filter per i filtri -->
<livewire:gestionale-header-filter>
<!-- fine import del componente gestionale header filter -->
<hr />
<!-- import dei component livewire (tab: partite, pratiche, articoli) -->
<livewire:table-pratiche />
<hr />
<livewire:table-partite />
<hr />
<livewire:table-articoli />
<!-- fine dell'import dei component livewire (tab: partite, pratiche, articoli) -->
<!-- import del component contenente i button per aprire i modal -->
<livewire:gestionale-modal-component />
<a class="btn btn-secondary" href="{{ url('tenants/' .$idt) }}">Torna alla dashboard</a>
</div>
<!-- Inizio dei modal per gestire le azioni del gestionale -->
<!-- modal per l'inserimento di un pagamento -->
<div class="modal fade" id="PagamentoLongModal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Aggungi un pagamento</h5>
<button type="button" class="close" data-dismiss="modal"><span>×</span>
</button>
</div>
<div class="basic-form">
<form id="formAddPagamento" method="POST" action="{{ url('/tenants/'.$idt.'/gestionale/addPagamento') }}">
#csrf
<div class="modal-body">
<!-- corpo del form popolato dinamicamente -->
</div>
<div class="modal-footer">
<input type="submit" class="btn btn-primary" value="Aggiungi pagamento">
<button type="button" class="btn btn-danger light" data-dismiss="modal">Chiudi</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- modal per l'inserimento di un assegnatario -->
<div class="modal fade bd-example-modal-lg" tabindex="-1" id="assegnatarioModal" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Aggiungi un assegnatario</h5>
<button type="button" class="close" data-dismiss="modal"><span>×</span>
</button>
</div>
<div class="basic-form">
<form id="formAddAssegnatario" method="POST" action="{{ url('/tenants/'.$idt.'/gestionale/addAssegnatario') }}">
#csrf
<div class="modal-body">
<!-- corpo del form popolato dinamicamente -->
</div>
<div class="modal-footer">
<input type="submit" class="btn btn-primary" value="Aggiungi assegnatario">
<button type="button" class="btn btn-danger light" data-dismiss="modal">Chiudi</button>
</div>
</form>
</div>
</div>
</div>
</div>
<!-- modal per visualizzare i pagamenti associati alla partita -->
<div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true" id="ShowPagamentiModal">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Pagamenti associati alla partita</h5>
<button type="button" class="close" data-dismiss="modal"><span>×</span>
</button>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover table-responsive-sm">
<thead>
<tr>
<th>Ente</th>
<th>Minuta</th>
<th>Minuta partita</th>
<th>Anno rif.</th>
<th>Agente Riscossione</th>
<th>Anno ruolo</th>
<th>#ruolo</th>
<th>Codice Fiscale</th>
<th>Denominazione</th>
<th>ID cartella</th>
<th>Carico €</th>
<th>Progressivo riscossione</th>
<th>Data pagam.</th>
<th>Data reg.</th>
<th>Tipo pagam</th>
<th>Modalità pagamento</th>
</tr>
</thead>
<div class="modal-body-table">
</div>
</table>
</div>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
<!-- modal per visualizzare le procedure e le inesigibilita associati alla partita -->
<div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-hidden="true"
id="ProcedureInesigibilitaModal">
<div class="modal-dialog modal-xl">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Procedure e Inesigibilità</h5>
<button type="button" class="close" data-dismiss="modal"><span>×</span>
</button>
</div>
<div class="modal-body">
<!-- da aggiungere il corpo del body -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger light" data-dismiss="modal">Chiudi</button>
<button type="button" class="btn btn-primary">Salva</button>
</div>
</div>
</div>
</div>
<!-- fine dei modal per gestire le azioni del gestionale -->
<script>
//SCRIPT PER L'APERTURA DINAMICA DEI MODAL A SECONDA CHE SIANO SELEZIONATE O MENO LE OPPORTUNE RIGHE DELLE TABELLE NELLA PAGINA
// INIZIO ACTION PER APERTURA E CHIUSURA DINAMICA DEL MODAL 'AGGIUNGI PAGAMENTO'
window.addEventListener('openPagamentoLongModal', event => {
console.log(event.detail.articolo[0]);
$(".modal-body").empty();
$(".modal-footer").empty();
$(".modal-body").append('<input type="text" hidden name="ida" id="articolo" placeholder="' + event.detail.id_articolo + '" value="'+event.detail.id_articolo+'"/>');
$(".modal-body").append('<input type="text" hidden name="idp" id="partita" placeholder="' + event.detail.articolo[0].idp + '" value="'+event.detail.articolo[0].idp+'"/>');
$(".modal-body").append('<div class="form-group row"><label class="col-sm-3 col-form-label">Presso</label><div class="col-sm-9"><input type="text" class="form-control input-rounded" placeholder="Ente"></div></div>');
$(".modal-body").append('<div class="form-group row"><label class="col-sm-3 col-form-label">Partita</label><div class="col-sm-9"><input type="text" readonly class="form-control input-rounded" name="partita" value="'+event.detail.articolo[0].partita+'"></div></div>');
$(".modal-body").append('<div class="form-group row"><label class="col-sm-3 col-form-label">Anno riferimento</label><div class="col-sm-9"><input type="text" readonly class="form-control input-rounded" name="anno_rif" value="'+event.detail.articolo[0].anno_rif+'"></div></div>');
$(".modal-body").append('<div class="form-group row"><label class="col-sm-3 col-form-label">Anno</label><div class="col-sm-9"><input type="text" readonly class="form-control input-rounded" name="anno_ruolo" value="'+event.detail.articolo[0].anno_ruolo+'"></div></div>');
$(".modal-body").append('<div class="form-group row"><label class="col-sm-3 col-form-label">Numero</label><div class="col-sm-9"><input type="text" readonly class="form-control input-rounded" name="num_ruolo" value="'+event.detail.articolo[0].ruolo+'"></div></div>');
$(".modal-body").append('<div class="form-group row"><label class="col-sm-3 col-form-label">Carico</label><div class="col-sm-9"><input type="text" readonly class="form-control input-rounded" name="carico" value="'+event.detail.articolo[0].carico+'"></div></div>');
$(".modal-body").append('<hr>');
$(".modal-body").append('<div class="form-group row"><label class="col-sm-3 col-form-label">Tipologia</label><div class="col-sm-9"><select class="form-select input-rounded form-select-lg mb-3" aria-label=".form-select-lg example" name="tipologia"><option value="sgravio">Sgravio</option><option value="normale">Normale</option></select></div></div>');
$(".modal-body").append('<option value="sgravio">Sgravio</option>');
$(".modal-body").append('<option value="normale">Normale</option>');
$(".modal-body").append('</select></div></div>');
$(".modal-body").append('<div class="form-group row"><label class="col-sm-3 col-form-label">Imposta</label><div class="col-sm-9"><input type="number" step=".01" class="form-control input-rounded" name="imposta"></div></div>');
$(".modal-body").append('<div class="form-group row"><label class="col-sm-3 col-form-label">Mora</label><div class="col-sm-9"><input type="number" step=".01" class="form-control input-rounded" name="mora"></div></div>');
$(".modal-body").append('<div class="form-group row"><label class="col-sm-3 col-form-label">Data Pagamento</label><div class="col-sm-9"><input type="date" class="form-control input-rounded" name="data_pag"></div></div>');
$(".modal-body").append('<div class="form-group row"><label class="col-sm-3 col-form-label">Data Registrazione</label><div class="col-sm-9"><input type="date" class="form-control input-rounded" name="data_reg"></div></div>');
$(".modal-body").append('<div class="form-group row"><label class="col-sm-3 col-form-label">Note</label><div class="col-sm-9"><input type="text" class="form-control input-rounded" name="note"></div></div>');
if(event.detail.articolo[0].residuo > 0){
$(".modal-footer").append('<input type="submit" class="btn btn-primary" value="Aggiungi pagamento">');
$(".modal-footer").append('<button type="button" class="btn btn-danger light" data-dismiss="modal">Chiudi</button>');
}else{
$(".modal-footer").append('<button type="button" class="btn btn-danger light" data-dismiss="modal">Chiudi</button>');
}
$("#formAddPagamento").append('#csrf()');
$("#PagamentoLongModal").modal('show');
})
window.addEventListener('closePagamentoLongModal', event => {
$("#PagamentoLongModal").modal('hide');
})
// FINE ACTION PER APERTURA E CHIUSURA DINAMICA DEL MODAL 'AGGIUNGI PAGAMENTO'
// INIZIO ACTION PER APERTURA E CHIUSURA DINAMICA DEL MODAL 'AGGIUNGI ASSEGNATARIO'
window.addEventListener('openassegnatarioModal', event => {
$(".modal-body").empty();
$(".modal-footer").empty();
$(".modal-body").append('<input type="text" hidden name="id_pratica" id="pratica" placeholder="' + event.detail.id_pratica + '" value="'+event.detail.id_pratica+'"/>');
$(".modal-body").append('<div class="form-group row"><label>Seleziona un assegnatario per la pratica:</label>');
$(".modal-body").append('<select class="form-select input-rounded form-select-lg mb-3" aria-label=".form-select-lg example" name="assegnatario"><option value="'+event.detail.assegnatario[0].id+'">'+event.detail.assegnatario[0].username+'</option></select></div>');
$(".modal-footer").append('<input type="submit" class="btn btn-primary" value="Aggiungi assegnatario">');
$(".modal-footer").append('<button type="button" class="btn btn-danger light" data-dismiss="modal">Chiudi</button>');
$("#formAddAssegnatario").append('#csrf()');
$("#assegnatarioModal").modal('show');
})
window.addEventListener('closassegnatarioModal', event => {
$("#assegnatarioModal").modal('hide');
})
// FINE ACTION PER APERTURA E CHIUSURA DINAMICA DEL MODAL 'AGGIUNGI ASSEGNATARIO'
// INIZIO ACTION PER APERTURA E CHIUSURA DINAMICA DEL MODAL 'PAGAMENTI ASSOCIATI'
window.addEventListener('openShowPagamentiModal', event => {
// Qui dobbiamo passare la lista dei pagamenti associati alla partita
$(".modal-body-table").empty();
$(".modal-footer").empty();
$(".modal-body-table").append('TODO');
$(".modal-footer").append('<button type="button" class="btn btn-danger light" data-dismiss="modal">Chiudi</button>');
$(".modal-footer").append('<button type="button" class="btn btn-primary"><i class="fa fa-print" aria-hidden="true"></i>Stampa</button>');
$("#ShowPagamentiModal").modal('show');
})
window.addEventListener('closeShowPagamentiModal', event => {
$("#ShowPagamentiModal").modal('hide');
})
// FINE ACTION PER APERTURA E CHIUSURA DINAMICA DEL MODAL 'PAGAMENTI ASSOCIATI'
// INIZIO ACTION PER APERTURA E CHIUSURA DINAMICA DEL MODAL 'PROCEDURE/INESIGIBILITA'
window.addEventListener('openProcedureInesigibilitaModal', event => {
// Qui dobbiamo passare la lista delle procedure e inesigibilita associate
$(".modal-body").empty();
$(".modal-body").append('<h3>Procedure associate</h3>');
$(".modal-body").append('<p>Lista delle procedure associate alla partita</p>');
$(".modal-body").append('<hr/>');
$(".modal-body").append('<h3>Inesigibilità associate</h3>');
$(".modal-body").append('<p>Lista delle inesigibilità associate alla partita</p>');
$("#ProcedureInesigibilitaModal").modal('show');
})
window.addEventListener('closeProcedureInesigibilitaModal', event => {
$("#ProcedureInesigibilitaModal").modal('hide');
})
// FINE ACTION PER APERTURA E CHIUSURA DINAMICA DEL MODAL 'PROCEDURE/INESIGIBILITA'
</script>
<!-- IMPORTANTE: AGGIUNGERE IL CSRF TOKEN PRIMA DI ANDARE IN PRODUZIONE -->
#endsection
table-pratiche.blade.php ( livewire component )
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<h4 class="card-title">Pratiche</h4>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="table table-hover table-responsive-md" id="tblpratiche">
<thead>
<tr>
<th>Soggetto</th>
<th>Codice Fiscale</th>
<th>Indirizzo</th>
<th>Tipo di imposta</th>
<th>Carico</th>
<th>Riscosso</th>
<th>Sgravio</th>
<th>Residuo</th>
<th>Assegnatario</th>
<th>Data assegn.</th>
<th>Dettagli</th>
</tr>
</thead>
<livewire:table-pratiche-content />
table-pratiche-content.blade.php ( livewire component )
<tbody>
#if (!empty($pratiche))
<?php
$carico = 0;
$riscosso = 0;
$sgravio = 0;
$residuo = 0;
$first = null;
$last =null;
$current = null;
$next = null;
$prev = null;
?>
#foreach ($pratiche['data'] as $p)
<tr wire:click="clickPartiteTrigger({{ $p['id_minuta'] }})" onclick="toggleClass(this, 'table-info')">
<td>#if(isset($p['denominazioneSoggetto'])) {{ $p['denominazioneSoggetto'] }} #else - #endif</td>
<td>#if(isset($p['codiceFiscale'])) {{ $p['codiceFiscale'] }} #else - #endif</td>
<td>#if(isset($p['indirizzoPOSTA'])) {{ $p['indirizzoPOSTA'] }} #else - #endif</td>
<td>#if(isset($p['descrizione_sintetica']) && $p['descrizione_sintetica'] != '' ) {{ $p['descrizione_sintetica'] }} #else - #endif</td>
<td>#if(isset($p['carico'])) {{ $p['carico'] }} € #else - #endif</td>
<td>#if(isset($p['riscosso'])) {{ $p['riscosso'] }} € #else - #endif</td>
<td>#if(isset($p['sgravio'])) {{ $p['sgravio'] }} € #else - #endif</td>
<td>#if(isset($p['residuo'])) {{ $p['residuo'] }} € #else - #endif</td>
<td>#if(isset($p['collaboratore'])) {{ $p['collaboratore'] }} #else - #endif</td>
<td>#if(isset($p['data_assegnazione'])) {{ $p['data_assegnazione'] }} #else - #endif</td>
#if($p['residuo']>0)
<td><span class="badge light badge-warning">Non riscosso</span></td>
#else
<td><span class="badge light badge-success">Riscosso</span></td>
#endif
<?php
$carico = $carico + $p['carico'];
$riscosso = $riscosso + $p['riscosso'];
$sgravio = $sgravio + $p['sgravio'];
$residuo = $residuo + $p['residuo'];
?>
</tr>
#endforeach
<?php
$first = $pratiche['first_page_url'];
$last = $pratiche['last_page_url'];
$current = $pratiche['current_page'];
$next = $pratiche['next_page_url'];
$prev = $pratiche['prev_page_url'];
?>
#endif
</tbody>
<livewire:tbl-pratiche-footer-filter :carico="$carico" :riscosso="$riscosso" :sgravio="$sgravio" :residuo="$residuo"
:first="$first" :last="$last" :current="$current" :next="$next" :prev="$prev" :pratiche="$pratiche" />
#push('custom_scripts')
<script type="text/javascript">
function toggleClass(el, className) {
if (el.className.indexOf(className) >= 0) {
el.className = el.className.replace(className,"");
}
else {
el.className += className;
}
}
</script>
#endpush
I have a user role called vendor which is one level below the super admin. I am trying to pull just the authenticated vendor's records in the index view but haven't had any luck. I can see the table in the view (which shows no records) and I can create a new record view the ui I have created. The fact is, I have no idea how to pull the current authenticated user's vendor records to the view. I am getting no errors in the console. Here are the following files.
in my vendorEmpresaContoller.php here is the index function
class vendorEmpresaController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
$empresa = Empresa::where('id', Auth::id())->get();
return view('vendor.empresas.index')->with('empresas', $empresa);
}
Vendor Middle ware
vendorMiddleware.php
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class VendorMiddleware
{
/**
* Handle an incoming request.
*
* #param \Illuminate\Http\Request $request
* #param \Closure $next
* #return mixed
*/
public function handle($request, Closure $next)
{
if (Auth::user()->role_as == 'vendor') {
if (Auth::check() && Auth::user()->isBanned) {
$banned = Auth::user()->isBanned == "1";
Auth::logout();
if ($banned == 1) {
$message = 'Your account has been Banned. Please contact the administrator.';
}
return redirect()->route('login')->with('status', $message)->withErrors(['email' => 'Your account has been Banned. Please contact the administrator.']);
}
return $next($request);
} else {
return redirect('/home')->with('status', 'You are not permitted to access the vendor dashboard');
}
}
}
User.php as my Model
<?php
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Cache;
class User extends Authenticatable
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* #var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function isUserOnline()
{
return Cache::has('user-is-online' . $this->id);
}
public function empresas()
{
return $this->hasMany('App\Empresa');
}
}
and my Empresa Model (relevant code only)
Empresa.php
public function empresas()
{
return $this->hasMany('App\Empresa');
}
And finally, in my index (the view I am trying to present the records) index.blade.php
#extends('layouts.vendor-admin')
#section('content')
<!-- Start delete modal-->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<h4 class="modal-title w-100 font-weight-bold">Borrar</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="/delete-empresa" method="POST" id="deleteForm">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<div class="modal-body mx-3">
<input type="hidden" name="_method" value="DELETE">
<div class="text-center">
<i class="fas fa-exclamation-triangle mb-4" style="color: #ffc107; font-size: 32px;"></i>
</div>
<h3 class="text-center text-uppercase">¿Estás Seguro/a?
</h3>
</div>
<div class="modal-footer d-flex justify-content-center">
<button class="btn btn-primary" data-dismiss="modal">Cancelar</button>
<button type="submit" class="btn btn-danger">Sí, Borralo!</button>
</div>
</form>
</div>
</div>
</div>
<!--end delete modal-->
<div class="container-fluid mt-5">
<!-- Heading -->
<div class="card mb-4 wow fadeIn">
<!--Card content-->
<div class="card-body d-sm-flex justify-content-between">
<h4 class="mb-2 mb-sm-0 pt-1">
Inicio
<span>/</span>
<span>Empresas Registradas</span>
</h4>
#if (session('status'))
<div class="alert alert-success fade-message" role="alert">
{{ session('status') }}
</div>
#endif
<div class="modal fade" id="modalRegisterForm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header text-center">
<h4 class="modal-title w-100 font-weight-bold">Añadir Empresa</h4>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<form action="/vendor-empresas" method="POST">
{{ csrf_field() }}
<div class="modal-body mx-3">
<div class="md-form mb-1">
<input type="text" name="erfc" id="orangeForm-erfc" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-erfc">RFC</label>
</div>
<div class="md-form mb-1">
<input type="text" name="enombre" id="orangeForm-enombre" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-enombre">Nombre</label>
</div>
<div class="md-form mb-1">
<input type="text" name="ecalle" id="orangeForm-ecalle" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-ecalle">Calle</label>
</div>
<div class="md-form mb-1">
<input type="text" name="ecolonia" id="orangeForm-ecolonia" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-ecolonia">Colonia</label>
</div>
<div class="md-form mb-1">
<input type="text" name="eciudad" id="orangeForm-eciudad" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-eciudad">Ciudad</label>
</div>
<div class="md-form mb-1">
<input type="text" name="eestado" id="orangeForm-eestado" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-eestado">Estado</label>
</div>
<div class="md-form mb-1">
<input type="text" name="ecpostal" id="orangeForm-ecpostal" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-ecpostal">Codigo Postal</label>
</div>
<div class="md-form mb-1">
<input type="text" name="epais" id="orangeForm-epais" class="form-control validate">
<label data-error="wrong" data-success="right" for="orangeForm-epais">País</label>
</div>
<div style="display: none;" class="md-form mb-1">
<input type="text" name="euser" readonly id="orangeForm-euser" class="form-control validate" value="{{ Auth::user()->id }}">
</div>
<div style="display: none;" class="md-form mb-1">
<input type="text" name="eregby" readonly id="orangeForm-eregby" class="form-control validate" value="{{ Auth::user()->id }}">
</div>
</div>
<div class="modal-footer d-flex justify-content-center">
<button type="submit" class="btn btn-deep-orange">Añadir</button>
</div>
</form>
</div>
</div>
</div>
<div class="text-center">
<i class="fa fa-plus" aria-hidden="true"></i> Añadir
</div>
</div>
</div>
<!-- Heading -->
<!--Grid row-->
<!--Grid column-->
<div class="row">
<!--Card-->
<div class="col-md-12 mb-4">
<!--Card content-->
<div class="card">
<!-- List group links -->
<div class="card-body">
<table id="datatable2" class="table table-bordered">
<thead>
<tr>
<th style="display: none;">ID</th>
<th>RFC</th>
<th>Nombre</th>
<th>Calle</th>
<th>Colonia</th>
<th>Ciudad</th>
<th>Estado</th>
<th>Codigo Postal</th>
<th>País</th>
<th>Acción</th>
</tr>
</thead>
<tbody>
#foreach ($empresas as $empresa)
<tr>
<input type="hidden" name="id" value="{{ $empresa->id }}">
<td style="display: none;">{{ $empresa->id }}</td>
<td>{{ $empresa->erfc }}</td>
<td>{{ $empresa->enombre }}</td>
<td>{{ $empresa->ecalle }}</td>
<td>{{ $empresa->ecolonia }}</td>
<td>{{ $empresa->eciudad }}</td>
<td>{{ $empresa->eestado }}</td>
<td>{{ $empresa->ecpostal }}</td>
<td>{{ $empresa->epais }}</td>
<td>
<div class="text-center">
<a class="badge badge-pill btn-primary px-3 py-2" href="{{ url('edit-empresa/'.$empresa->id) }}">Editar</a>
<a class="delete badge badge-pill btn-danger px-3 py-2">Borrar</a>
</div>
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
<!-- List group links -->
</div>
</div>
<!--/.Card-->
</div>
<!--Grid row-->
</div>
#endsection
#section('scripts')
<script>
$(document).ready(function() {
let table = $('#datatable2').DataTable();
// Start Delete Record
table.on('click', '.delete', function() {
$tr = $(this).closest('tr');
if($($tr).hasClass('child')) {
$tr = $tr.prev('.parent')
}
let data = table.row($tr).data();
console.log(data);
$('#deleteForm').attr('action', '/delete-empresa/'+data[0]);
$('#deleteModal').modal('show');
});
// End Delete Record
});
</script>
<script>
$(document).ready(function($) {
$(function() {
setTimeout(function() {
$('.fade-message').slideUp();
}, 3000);
});
});
</script>
#endsection
Here is the Database showing the record I am trying to retrieve which is user with the id 18.
Since I am new to Laravel (a complete noob) I really appreciate the help in getting the records visible. Thank you in advance for your help.