envoyer une variable à la vue.

Par Soumah Abdoul Salam, il y a 10 ans


salut je n'arrive pas à envoyer une variable à la vue. Voici ma founction
public function postLignecommande(){
$rules['article_code'] = 'required';
$rules['commande_code'] = 'required';
$rules['quantite'] = 'required|numeric';
$validation = Validator::make(Input::all(), $rules);
if($validation->fails()){
return Redirect::to('showvente/show')
->withInput()
->withErrors($validation)
->with('erreurs',$validation->messages());
}else{
$ligneCommande = new LigneCommande();
$ligneCommande->article_code = Input::get('article_code');
$ligneCommande->commande_code = Input::get('commande_code');
$ligneCommande->quantite = Input::get('quantite');
if( $ligneCommande->save()){
$listeProduit = DB::table('ligne_commandes')
->join('articles','articles.code','=','ligne_commandes.article_code')
->join('commandes','commandes.code','=','ligne_commandes.commande_code')
->where('commandes.client_code','=',Input::get('commande_code'))->get();
return View::make('bmstemplate.vente')
->with('succes','Insertion effecuer avec succès')
->with('listeProduit',$listeProduit);
}
}
}

10 réponses

guigui23, il y a 10 ans

A oui c'est vrai dsl pour la gourde :|

Azorgh, il y a 10 ans

Tu peux mettre ton code en forme s'il te plait ?
Sinon oui tu y arrive pas, mais tu as debug ? Tu as fait des die et des var_dump un peu partout au niveau controller puis vue ?

Soumah Abdoul Salam, il y a 10 ans

le contenu de ma variable est vide lors ce que je l'envoi à la vue

Crazyweeds, il y a 10 ans

Fais un dd() sur ta variable juste avant de l'envoyer à la vue pour voir si elle n'est pas vide quand tu l'envoie

connected, il y a 10 ans

Bonjour,

As-tu des messages d'erreur ? Si oui est-ce que tu peux nous les donner.
Je reposte ton code tel quel avec la mise en forme, juste pour mieux voir :

public function postLignecommande(){ $rules['article_code'] = 'required'; $rules['commande_code'] = 'required'; $rules['quantite'] = 'required|numeric'; $validation = Validator::make(Input::all(), $rules); if($validation->fails()){ return Redirect::to('showvente/show') ->withInput() ->withErrors($validation) ->with('erreurs',$validation->messages()); }else{ $ligneCommande = new LigneCommande(); $ligneCommande->article_code = Input::get('article_code'); $ligneCommande->commande_code = Input::get('commande_code'); $ligneCommande->quantite = Input::get('quantite'); if( $ligneCommande->save()){ $listeProduit = DB::table('ligne_commandes') ->join('articles','articles.code','=','ligne_commandes.article_code') ->join('commandes','commandes.code','=','ligne_commandes.commande_code') ->where('commandes.client_code','=',Input::get('commande_code'))->get(); return View::make('bmstemplate.vente') ->with('succes','Insertion effecuer avec succès') ->with('listeProduit',$listeProduit); } } }
guigui23, il y a 10 ans

Salut,
je dirais plutôt,

return View::make('bmstemplate.vente',compact($listeProduit)) ->with('succes','Insertion effecuer avec succès');

Il me semble que le with gère un flash session.

Azorgh, il y a 10 ans

Laravel 4 ou 5 ? (J'aurais dit 4, mais jamais bossé sous le 4)

Alexandre #lbac, il y a 10 ans
return view('ton file', compact('listeProduit'))->with('success', 'Insertion effectuée avec succès');
Martin, il y a 10 ans

Hello,

il me semble que la fonction compact prend en parametre un string ou un tableau de string.

compact("listeProduit")

Je ne pense pas que cela fonctionnera avec

compact($listeProduit)
Azorgh, il y a 10 ans

Oui Martin :

$uneVar = 'truc'; $uneVar2 = 'much' return view('view.view', compact('uneVar', 'uneVar2'));