Hello I am working with laravel and livewire and I'm trying to resolve this error for a chat room, can anyone help me please? :
Illuminate\Contracts\Container\BindingResolutionException Unable to
resolve dependency [Parameter #0 [ $message ]] in class
App\Http\Livewire\ChatRoom
this is the concerned function in LettresController.php
public function ChoisirLettresAléatoiresDuReserve(){
// Messages de la btcom
$message=Message::all();
$user_id = auth()->id();
// check if there is game in the request
if (!request()->has('game')) {
return redirect()->route('game.select');
}
// getting game ID and fetching game
$game = $this->get_game_by_id((int)request()->get('game'));
// check if the game has finished or is still running
if ($this->check_game_finished($game)) {
$this->update_game_timer($game, $user_id);
// user has used up his chevalet, so we need to update with new
$position = $this->user_chevalet_position($game, $user_id);
if ($position === null) {
// user might have entered a game id but was never part of the game
return redirect()->route('game.select');
}
// get if the player has no more playing piece left
$user_chevalet = $this->get_user_chevalet($game, $user_id, $position);
$valeur = $this->generate_valeur($user_chevalet);
$game = $this->get_game_by_id((int)request()->get('game'));
return view('jeu')->with(compact('game', 'valeur', 'position','message'));
}
return redirect()->route('game.ended')->with(['Resultat' => 'Game Ended']);
}
and I am using livewire
livewire.ChatRoom.php
<?php
namespace App\Http\Livewire;
use App\Traits\GameTraits;
use Livewire\Component;
use Carbon;
class ChatRoom extends Component
{
public $newMessage;
public $photo;
public $messages;
public function mount($message){
// dd($message);
$this->messages = $message;
}
public function addMessage($message)
{
if($this->newMessage==''){
return;
}
array_unshift($this->messages,[
'contenu' => $this->newMessage,
'created_at' => \Carbon\Carbon::now()->diffForHumans(),
'user_id'=> 'Ness'
]);
}
public function render()
{
return view('livewire.chat-room');
}
}
chat-room.blade.php
<div class="container" id="positionbt">
<div class="row">
<div class="col-md-8 col-md-offset-2 bootstrap snippets bootdeys" >
<div class="widget-container scrollable list rollodex">
<div class="heading" id="btc">
<span class="fa"></span> Boite de communication
</div>
<div class="panel-body">
<ul class="chat">
<li class="left clearfix"><span class="chat-img pull-left" >
<img width="40" height="40" src="{{ asset('img/scrabblelogo.png') }}" alt="User Avatar" class="img-circle" />
</span>
<div class="chat-body clearfix" class="text">
<div class="header">
<strong class="primary-font">!Aide</strong>
</div>
<div class="text">
<p>
Bonjour! Afin de pouvoir effectuer les tâches ci-dessous, vous pouvez utiliser ces 5 commandes:<br>
<b>1. Placer un mot:</b> !placer ligne colonne (h|v) mot<br>
<b>2. Changer une lettre:</b> !changer lettre<br>
<b>3. Passer le tour à un autre joueur:</b> !passer<br>
<b>4. Afficher le menu d'aide:</b> !aide<br>
<b>5. Quitter menu d'aide:</b> !quitter<br>
</p>
</div>
</div>
</li>
#foreach ($messages as $message)
<li class="left clearfix"><span class="chat-img pull-left">
<img width="40" height="40" src="{{ $message->post_by->photo }}" alt="User Avatar" class="img-circle" />
</span>
<div class="chat-body clearfix">
<div class="header">
<strong class="primary-font">{{ $message->post_by->nick }}</strong> <small class="pull-right text-muted">
<span class="glyphicon glyphicon-time"></span>{{ $message->created_at }}</small>
</div>
<p>
{{ $message->contenu }}
</p>
</div>
</li>
#endforeach
</div>
<form class="panel-footer" id="msg" wire:submit.prevent="addMessage">
<div class="input-group">
<input id="btn-input" type="text" class="form-control input-sm" placeholder="Tapez votre message ici..." wire:model="newMessage"/>
<span class="input-group-btn" style="padding-top: 8px;">
<button class="btn btn-primary btn-sm" id="btn-chat" type="submit">
Envoyer</button>
</span>
</div>
</form>
</div>
</div>
</div>
</div>
I included this in jeu.blade.php
<div class="btcom">
<livewire:chat-room :message="$message"/>
</div>
and my root in web.php is below:
Route::get('/jeu', [App\Http\Controllers\LettresController::class, 'ChoisirLettresAléatoiresDuReserve'])->name('jeu');
Ok, trying to understand the goal you pursuit you can handle like this, after we can do by better way
return redirect()->route('jeu.message',['game'=> $game, 'valeur'=>$valeur, 'position' => $position,'message' => $message]);
in web.php
Route::get('/jeu/{message}', function($message){
// dd($message);
return view('jeu',['message'=>$message]);
})->name('jeu.message');
This way, you can check if inside the method when this route is load it's passing the message value and you inject it into the blade and this way can be bind by the nested component
Related
I am currently trying to display todos in my app-todo view, but I keep getting the error mentioned in the title.
In my controller I have:
public function index()
{
$todos = Todo::all();
return view('content.apps.todo.app-todo', ['todos' => $todos]);
}
and in my app-todo:
<div class="todo-task-list-wrapper list-group">
<ul class="todo-task-list media-list" id="todo-task-list">
#foreach($todos as $todo)
<li class="todo-item">
<div class="todo-title-wrapper">
<div class="todo-title-area">
<i data-feather="more-vertical" class="drag-icon"></i>
<div class="title-wrapper">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="customCheck1" />
<label class="form-check-label" for="customCheck1"></label>
</div>
<span class="todo-title">Drink more water</span>
</div>
</div>
<div class="todo-item-action">
<div class="badge-wrapper me-1">
<span class="badge rounded-pill badge-light-primary">Team</span>
</div>
<small class="text-nowrap text-muted me-1">Aug 08</small>
<div class="avatar">
<img
src="{{asset('images/portrait/small/avatar-s-4.jpg')}}"
alt="user-avatar"
height="32"
width="32"
/>
</div>
</div>
</div>
</li>
#endforeach
I have tried changing the code in the controller to return view('content.apps.todo.app-todo')->with(['todos' => $todos]); and using compact('todos'); ,but I get the same error.
Update:
The model is the following:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Todo extends Model
{
protected $fillable = ['todoTitleAdd','task_assigned','task_due-date','task_tag', 'task_desc'];
}
and the web.php route:
Route::resource('todos', TodoController::class);
public function index(){
$todos = Todo::all();
return view('content.apps.todo.app-todo',compact('todos'));
}
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
Im currently learning to do sign in and sign up in laravel8 by referring some tutorials. But after sign up im getting this Undefined offset: 1 message.
Error line that showing is
$iteratee = trim($matches[1]);
This is my route file(web.php)
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
Route::get('/signup',[
'uses' =>'App\Http\Controllers\UserController#getSignup',
'as'=>'user.signup'
]);
Route::post('/signup',[
'uses' =>'App\Http\Controllers\UserController#getSignup',
'as'=>'user.signup'
]);
And this is the signup page register part
<header class="masthead" >
<div class="container">
<div class="masthead-subheading"></div>
<div class="masthead-heading text-uppercase"></div>
<div class="container">
<div class="card bg-light">
<article class="card-body mx-auto" style="max-width: 400px;">
<h4 class="card-title mt-3 text-center">Create Account</h4>
<p class="text-center">Get started with your free account</p>
#if(count($errors) > 0)
<div class="alert alert-danger">
#foreach($errors->all()as $error)
<p>{{$error}}</p>
#endforeach
</div>
#endif
<form action="{{ route('user.signup')}}">
<div class="form-group input-group">
<div class="input-group-prepend">
<span class="input-group-text"> <i class="fa fa-envelope"></i> </span>
</div>
<input name="email" class="form-control" placeholder="Email address" type="email">
</div>
<div class="form-group input-group">
<div class="input-group-prepend">
<span class="input-group-text"> <i class="fa fa-lock"></i> </span>
</div>
<input name="password" placeholder="Create password" type="password">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block"> Create Account </button>
{{csrf_field()}}
</div> <!-- form-group// -->
<p class="text-center">Have an account? Log In </p>
</form>
</article>
</div> <!-- card.// -->
</div>
<!--container end.//-->
</header>
UserController
class UserController extends Controller
{
public function getSignup()
{
return view('user.signup');
}
public function postSignup(Request $request)
{
$this->validate($request,[
'email'=> 'email|required|unique:users',
'password'=>'required|min:4'
]);
$user= new User([
'email'=>$request-> input('email'),
'password'=> bcrypt($request-> input('password'))
]);
$user-->save();
return redirect()->route('shop.index');
}
}
Please teach me a way to solve this.Thank you
You should add a space in the #foreach between the pieces:
#foreach($errors->all()as $error)
Should be:
#foreach($errors->all() as $error)
The Blade compiler parses the expression passed to this directive and does a preg_match on it to get the pieces of the expression as this directive does more than just creating a foreach loop. Here is the match on the expression:
preg_match('/\( *(.*) +as *(.*)\)$/is', $expression, $matches);
$iteratee = trim($matches[1]);
I have 2 table which are product and ps(seller). I want to make a page which will list all the seller product. I'm using if else statement but it is not working. I'm quite new in laravel, please help me.
PsController.php
public function show(){
$ps = DB::table('ps')->get();
return view('viewps', ['ps' => $ps]);
}
public function view($id){
$ps = Ps::find($id)
return view ('views')->with('ps', $ps);
}
public function sellitem(){
$id = DB::table('ps')->get();
$ps_id = DB::table('product')->get();
return view('sellitem', ['ps_id' => $ps_id,'id'=>$id]);
}
sellitem.blade.php
#if ($ps_id == $id)
<div class="searchable-container">
<div class="items col-xs-12 col-sm-6 col-md-6 col-lg-6 clearfix">
<div class="info-block block-info clearfix">
<div class="square-box pull-left">
<span class="glyphicon glyphicon-user glyphicon-lg"></span>
</div>
<h5>{{$ps_id->name}}</h5>
<h5><img src="{{ asset('images/' . $ps_id->image) }}" height="100" width="100"/> </h5>
<h5>Sold by : {{$ps_id->ps_name}}</h5>
<h4> <div class="panel-body"> </h4>
</div>
</div>
#else
No records found !
#endif
Route::get('/viewps', 'PsController#show');
Route::get('/viewps/{id}', 'PsController#view')->name('view');
Route::get('/home', 'HomeController#index')->name('home');
Route::get('/sellitem/{ps_id}', 'PsController#sellitem')->name('sellitem');
Product databaseps database
Update
PS model
class Ps extends Authenticatable{
use Notifiable;
protected $fillable = [
'name','lastname','email', 'password', 'username','phone','gender'
];
protected $hidden = [
'password', 'remember_token',
];
public function product(){
return $this->hasMany('Product::class'); }
Product model
class Product extends Model{
public $table = "Product";
protected $fillable =
['name','description','size','image','price','type','ps_id','ps_name'];
protected $hidden = [
'password', 'remember_token',
];
public function ps(){
return $this->belongsTo('Ps::class');
}
New update
What i want to do is , from viewps page there will be have a link to their sell item which is sellitem.
viewps.blade
<div class="box box-info">
<div class="box-body">
<div class="col-sm-6">
<div align="center"> <img alt="User Pic" src="https://x1.xingassets.com/assets/frontend_minified/img/users/nobody_m.original.jpg" id="profile-image1" class="img-circle img-responsive">
<input id="profile-image-upload" class="hidden" type="file">
</div>
<br>
</div>
<div class="col-sm-6">
<h4 style="color:#00b1b1;">{{ucfirst(trans($ps->name))}} {{ucfirst(trans($ps->lastname))}}</h4></span>
<span><p>Rating</p></span>
<span><p>Lists of Sell Items</p></span>
</div>
Sellitem.blade
#if (count($sellProducts) > 0)
#foreach ($ps as $sellProducts)
<div class="searchable-container">
<div class="items col-xs-12 col-sm-6 col-md-6 col-lg-6 clearfix">
<div class="info-block block-info clearfix">
<div class="square-box pull-left">
<span class="glyphicon glyphicon-user glyphicon-lg"></span>
</div>
<h5>{{$ps->name}}</h5>
<h5><img src="{{ asset('images/' . $ps->image) }}" height="100" width="100"/> </h5>
<h5>Sold by : {{$p->ps_name}}</h5>
<h4> <div class="panel-body"> </h4>
</div>
</div>
#endforeach
#else
No records found !
#endif
</div>
#endsection
Use the following query (We can also use DB::raw in the select statement to calculate sum orcount(*)` )
public function sellitem($id){
$ps = Ps::find($id);
$query = DB::table('ps')
->select('product.id as id',
'product.name as name',
'product.description as description',
'product.type as type',
'product.ps_id as ps_id',
'product.ps_name as ps_name',
'product.size as size',
'product.price as price'
))
->join('product', 'product.ps_id', '=', 'ps.id')
->where('product.ps_id','=', $id)
;
$results = $query->get();
return view('sellitem', ['sellProducts' => $results,'ps'=> $ps]);
}
Then in the sellitem.blade.php
use for loop to get values from sellProducts(in this case there will be no need of if condition )
#if (count($sellProducts) > 0)
#foreach ($sellProducts as $sp )
<div class="searchable-container">
<div class="items col-xs-12 col-sm-6 col-md-6 col-lg-6 clearfix">
<div class="info-block block-info clearfix">
<div class="square-box pull-left">
<span class="glyphicon glyphicon-user glyphicon-lg"></span>
</div>
<h5>{{$sp->name}}</h5>
<h5><img src="{{ asset('images/' . $sp->image) }}" height="100" width="100"/> </h5>
<h5>Sold by : {{$sp->ps_name}}</h5>
<h4> <div class="panel-body"> </h4>
</div>
</div>
#endforeach
#else
No records found !
#endif
In my users page, I use a div with two tabs "Products" and "Followers", in the second tab, I've a pagination for the list of followers.
Not return to the tab "Products" when I try the pagination, I user a call Ajax.
But when I try to run it, I have a error 500, and the response of the get is :
{"error":{"type":"ErrorException","message":"array_merge(): Argument #2 is not an
array","file":"\/Users\/utilisateur\/Desktop\/mamp\/ptf-l4\/vendor\/laravel\/framework\
/src\/Illuminate\/View\/Environment.php","line":117}}
I don't know why and I don't know how to find a solution.
This is my controller :
public function show($id){
// récupère les données de l'user et les produis qu'il partage
$show = $this->api->show($id);
// décode le json pour qu'il se réaffiche en array pour pouvoir l'exploiter
$json = json_decode($show->getContent());
$json->followed = User::userFollowedPaginate($id);
LaravelMixpanel::identify(Auth::user()->mixpanel_id);
LaravelMixpanel::track('User show view');
if(Request::ajax())
{
$html = View::make('users.show', $json)->render();
return Response::json(['html' => $html]);
}
return View::make('users.show')
->with('user', $json);
}
My API/Controller :
public function show($id){
// récupère donnée de l'user et les produits qu'il échange
$data = User::with(array('products' => function($query){
$query->whereNull('shared_at');
$query->whereNull('deleted_at');
}))->findOrFail($id)->toArray();
// récupère le nb de produits qu'il échange en ce moment
$data['nbShareCurrently'] = Product::where('user_id', $id)->whereNull('shared_at')->whereNull('deleted_at')->count();
// récupère le nb de produits qu'il a échangé depuis le début
$data['nbShared'] = Product::where('user_id', $id)->whereNotNull('shared_at')->count();
return Response::json($data, 200);
}
My JS :
function callAjaxUser(url) {
$.ajax ({
type: "GET",
url: url ,
success: function() {
console.log('Success ');
},
error: function() {
console.log('Error ');
}
});
}
$(document).ready(function(){
$('body').on('click', ' .pagination a ', function(event){
event.preventDefault();
var url=$(this).attr('href');
callAjaxUser(url);
});
});
And my view :
#extends('default')
#section('title')
Fiche de {{ $user->name }}
#stop
#section('contenu')
<section class="panel col-lg-8 col-sm-8 m-t-large">
<header class="panel-heading m-l-n m-r-n">
<ul class="nav nav-tabs pull-right">
<li class="active"><i class="icon-list icon-large text-default"></i>Mes produits en cours de partage</li>
<li><i class="icon-group icon-large text-default"></i>Mes abonnés</li>
</ul>
<span class="hidden-sm">Fiche technique du frigo</span>
</header>
<div class="panel-body">
<div class="tab-content">
<div class="tab-pane active" id="product">
<div class="col-lg-3">
{{-- dd($user) --}}
<h4>{{{ $user->name }}}</h4>
#if($user->photo && File::exists(public_path().'/uploads/photos/users/'.e($user->photo)))
{{ HTML::image('uploads/photos/users/'.e($user->photo), e($user->name)) }}
#else
{{ HTML::image('template/images/avatar.jpg', e($user->name)) }}
#endif
#if($user->id!=Auth::user()->id)
#if(DB::table('user_followers')->where('user_followed', $user->id)->where('user_following', Auth::user()->id)->count()==0)
{{ HTML::decode(HTML::linkAction('UserFollowersController#follow', '<i class="icon-heart">S\'abonner</i>', array('id' => $user->id), array('class' => 'btn btn-info m-t-large m-b-small'))) }}
#else
{{ HTML::decode(HTML::linkAction('UserFollowersController#unfollow', '<i class="icon-heart">Se désabonner</i>', array('id' => $user->id), array('class' => 'btn btn-danger m-t-large m-b-small '))) }}
#endif
#endif
</div>
<div class="col-lg-9">
<h4>Le frigo contient en ce moment :</h4>
<ul class="list-unstyled">
#foreach($user->products as $product)
<li class="list-group-item bg m-b-small">
<div class="media">
#if(e($product->photo) && File::exists(public_path().'/uploads/photos/products/'.e($product->photo)))
<span class="pull-left img-product">
<a href="{{ URL::action('ProductsController#show', $product->id) }}">
{{ HTML::image('uploads/photos/products/'.e($product->photo), e($product->title), array('class' => 'img-rounded')) }}
</a>
</span>
#endif
<div class="media-body">
<div>{{{ $product->title }}}</div>
<p>{{{ $product->description }}}</p>
<p class="pull-left">Quantité : <span class="label label-info">{{{ $product->quantity }}}</span></p>
<p class="pull-right">Prix : <span class="badge bg-danger">{{{ $product->price }}} €</span></p>
</div>
</div>
</li>
#endforeach
</ul>
<div class="pagination">
{{-- $users->products->links() --}}
</div>
</div>
</div>
<div class="tab-pane" id="follow">
<div class="row m-b-large">
#if($user->followed!=NULL)
#foreach($user->followed as $user_followed)
<div class="panel col-lg-2 m-l-large m-t-large ">
<div class="col-lg-8 m-b-n-small col-md-offset-2 m-t-large text-center">
#if($user_followed->photo && File::exists(public_path().'/uploads/photos/users/'.e($user_followed->photo)))
{{ HTML::image('uploads/photos/users/'.e($user_followed->photo), e($user_followed->name), array ( 'class' => 'img-circle')) }}
#else
{{ HTML::image('template/images/avatar.jpg', e($user_followed->name), array ( 'class' => 'img-circle')) }}
#endif
<h3>{{{ $user_followed->name }}}</h3>
</div>
<div class="col-lg-10 m-b-small center ">
#if(DB::table('user_followers')->where('user_followed', $user_followed->id)->where('user_following', Auth::user()->id)->count()==0)
{{ HTML::decode(HTML::linkAction('UserFollowersController#follow', '<i class="icon-heart">S\'abonner</i>', array('id' => $user_followed->id), array('class' => 'btn btn-info btn-group-justified m-t-large m-b-small'))) }}
#else
{{ HTML::decode(HTML::linkAction('UserFollowersController#unfollow', '<i class="icon-heart">Se désabonner</i>', array('id' => $user_followed->id), array('class' => 'btn btn-danger btn-group-justified m-t-large m-b-small '))) }}
#endif
</div>
</div>
#endforeach
#else
<div class="panel col-lg-8 col-lg-offset-2 m-t-large">
<h4> Tu ne suis actuellement personne </h4>
</div>
#endif
</div>
<div class="col-lg-12">
{{ $user->followed->links() }}
</div>
</div>
</div>
</div>
</section>
#stop
#section('js')
{{ Basset::show('usersPaginate.js') }}
#endsection
I stumbled upon this question because it is the first Google search result for laravel ErrorException, array_merge(): Argument #2 is not an array.
Even though the question is a year old, it is still relevant, because this happened to me in Laravel 5.0 today.
Without taking the time to digest all of your code, the problem is likely the same in your case as it was in mine: you are passing a non-array as the second argument to view::make() (whether intentionally or not) when you must pass an array.
The problem line is this one, in your controller:
$html = View::make('users.show', $json)->render();
Given that $json appears to be an object, the fix is simple:
$html = View::make('users.show', compact('json'))->render();
Hopefully, this answer will help somebody else in the future.