lundi 29 février 2016

Passing variable to view by with not working in laravel 5.1

I am new in laravel , I want to pass my variable to view by with this is my controller for example :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Prices ;

class PricesController extends Controller
{

        function getIndex()
        {
            $prices =   Prices::orderBy( 'id' , 'desc' )-> paginate(2) ;

            return view('home')->nest('content' , 'price', compact('prices')  )   ->with( [ 'title' => 'prices page' , 'message' => 'my message text ' ]) ;

        }
}

and this is my master.blade.php :

<!doctype html>
<html lang="fa">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>    {{ $title  }}</title>

    <link rel="stylesheet" href="{{ url()  }}/css/bootstrap.css">
    <link rel="stylesheet" href="{{ url()  }}/css/style.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="http://ift.tt/1fK4qT1"></script>
    <script src="http://ift.tt/1knl5gY"></script>

    <![endif]-->
</head>
<body>

<div class="container">
    @yield("main")
</div><!-- container -->



<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->

<script src="{{ url()  }}/js/bootstrap.min.js"></script>
<script src="{{ url()  }}/js/dropdown.js"></script>
<script src="{{ url()  }}/js/collapse.js"></script>
<script src="{{ url()  }}/js/transition.js"></script>
<script src="{{ url()  }}/js/tab.js"></script>
</body>
</html>

and this is home.blade.php :

@extends('master')

@section('main')
    @include('top_menu')

    <div class="row">
        <section class="col-sm-12 col-md-12   content">

            <div class="row">
                <section class="col-md-12">
                    <div class="in">
                        {!! $content !!}
                    </div>
                </section>
            </div>

        </section>
    </div>


@stop

and this is my price.blade.php :

@if(   empty($prices)     )
    <div class="alert alert-warning">
        No result
    </div>
@else


    @if( !   isset(  $message)     )
            No message
    @else
        {{ $message  }}

        @endif

    <table class="table table-striped">
        <tr>
            <th>name</th>
            <th>yeat</th>
            <th>qnty </th>
        </tr>

    @foreach( $prices as $price )
        <tr>
            <td>  {{$price->product}} </td>
            <td>  {{$price->yaer}} </td>
            <td>  {{$price->quantity}} </td>
        </tr>
    @endforeach
    </table>

    <center>    {!! $prices->render() !!} </center>


@endif

in Output title in <title> {{ $title }}</title> in master.balde.php is passed good and it will show : prices page in page title , But in this part in price.blade.php :

@if( !   isset(  $message)     )
        No message
@else
    {{ $message  }}

    @endif

the output is :

No maessage

how can I fix it ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire