Search option in product dropdown in Laravel - php

I have successfully done the product dropdown list with the select option but I am can't include the search option inside the dropdown. I have tried some code taken from Google but failed. I am new to Laravel and I don't know how to proceed further. Please help to include the search option.
Here is the code!
Blade:
<div class="row">
<div class="input-field col s12 m6">
{{ Form::select('customer', $customers, null, ['placeholder' => 'Select A Client ID' ,'required'=> '', 'aria-required' => 'true']) }}
</div>
<div class="input-field col s12 m6">
{{ Form::select('products[]', $products, null, ['multiple' => true, 'class' => 'validate multiple', 'required'=> '', 'aria-required' => 'true']) }}
</div>
</div>
Controller:
public function add()
{
$title = "Add New Order";
$customer_list = DB::table('accounts')->select('id', 'fname', 'lname')->where('account_type_id', '1')->get();
$product_list = DB::table('products')->select('id', 'name', 'quantity')->where('status', 1)->where('show_client', 1)->where('quantity', '>', 0)->get();
$customers = array();
foreach ($customer_list as $customer) {
$customers[$customer->id] = $customer->id;
}
$productss = array();
foreach ($product_list as $product) {
$productss[$product->id] = $product->name . " (" . $product->quantity . ")";
}
$pselect = array('value="" disabled selected' => 'Please Select Products');
$products = $pselect + $productss;
return view('order.add', compact('title', 'customers', 'products'));
}
Route:
// Orders Controller
Route::get('/order', 'OrderController#manage');
Route::get('/order/add', 'OrderController#add');
Route::post('/order/add_confirm', 'OrderController#addConfirm');
Route::post('/order/add_confirmed', 'OrderController#addConfirmed');
Route::get('/order/manage/{id}', 'OrderController#manageOrder');
Route::post('/order/manage/accept', 'OrderController#manageOrderStatus');
Route::post('/order/manage/pending', 'OrderController#manageOrderStatus');
Route::post('/order/manage/cancel', 'OrderController#manageOrderStatus');
Route::post('/order/manage/fraud', 'OrderController#manageOrderStatus');
Route::post('/order/manage/delete', 'OrderController#manageOrderStatus');
Route::post('/order/save_note', 'OrderController#manageOrderNote');
Route::post('/order/emi_calculation', 'OrderController#emiCalculation');
Route::get('/order/{name}', 'OrderController#manage');

Generally, avoid using the Form Helpers ie. {{ Form:: ... because they make the code too complicated and long without any real advantages. Use normal simple html form tags.
To search customers, try to use DATALIST HTML element but not the select. See here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/datalist
To populate the datalist with a default value, eg. select a customer, use its value property as shown below.
The following should work.
The web.php
Route::get('/order/add', 'OrderController#add'); //testing
The OrderController.php . Note I have just changed your initial queries for product and customers (my customers table is called partners) a bit to match my database tables and columns but the logic is still intact.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class OrderController extends Controller
{
//
public function add()
{
$title = "Add New Order";
// $customers = DB::table('accounts')->select('id', 'fname', 'lname')->where('account_type_id', '1')->get();
$customers = DB::table('partners')/*->select('id', 'fname', 'lname')->where('account_type_id', '1')*/->get();
//$products = DB::table('products')->select('id', 'name', 'quantity')->where('status', 1)->where('show_client', 1)->where('quantity', '>', 0)->get();
$products = DB::table('products')/*->select('id', 'name', 'quantity')->where('status', 1)->where('show_client', 1)->where('quantity', '>', 0)*/->get();
return view('order.add', compact('title', 'customers', 'products'));
}
}
The views/add.blade.php is as below.
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<title>Hello, world!</title>
</head>
<body>
<h1>Hello, world!</h1>
<div class="container">
<div class="row">
<div class="col-md-6">
<div class="input-field col s12 m6">
<input class="customers" list="customers" name="customer" value="Select A Customer" required>
<datalist id="customers">
#foreach($customers as $customer)
<option value="{{$customer->name}}" data-lname="{{$customer->name}}"
data-fname="{{$customer->name}}">
</option>
#endforeach
</datalist>
</div>
</div>
<div class="col-md-6">
<div class="input-field col s12 m6">
<label for="products">Add the new Products</label>
<select multiple class="form-control" id="products" name="products[]" required>
<option selected disabled value="Please select Products">Please select Products</option>
#foreach($products as $product)
<option value="{{$product->name .'('. $product->quantity .')'}}"
data-quantity="{{$product->quantity}}">{{$product->name .'('. $product->quantity .')'}}
</option>
#endforeach
</select>
</div>
</div>
</div>
</div>
<!-- Optional JavaScript; choose one of the two! -->
<!-- Option 1: jQuery and Bootstrap Bundle (includes Popper) -->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous">
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous">
</script>
<!-- Option 2: jQuery, Popper.js, and Bootstrap JS
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js#1.16.1/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#4.5.3/dist/js/bootstrap.min.js" integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script>
-->
</body>
</html>
Results:

I would suggest using something that already exists, Select2 is a package I've used for a long time and its really good
heres the link to their page : https://select2.org
all you have to do is include CSS and JS
<link href="https://cdn.jsdelivr.net/npm/select2#4.1.0-beta.1/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/select2#4.1.0-beta.1/dist/js/select2.min.js"></script>
then your html should be like this :
<select class="js-example-basic-single" name="state">
<option value="AL">Alabama</option>
...
<option value="WY">Wyoming</option>
</select>
and your JS:
// In your Javascript (external .js resource or <script> tag)
$(document).ready(function() {
$('.js-example-basic-single').select2();
});

Related

Undefined variable in Laravel trying to post source ID route

Currently Working on building out a news api behind a dashboard. I have just recently started getting the error Undefined variable: sourceId (View: C:\Laravel8Auth\resources\views\dashboard.blade.php).
Ive gone everywhere that has source Id and I cant see to figure out what it could be.
Here are some of the codes necessary, im using Laravel 8.x with JetStream Im fairly new at this just wanted to mess around.
web php
`<?php
use Illuminate\Support\Facades\Route;
use App\Models\Api;
use App\Http\Controllers\ApiController;
///Route::get('/', [ApiController::class,'displayNews']);
///Route::get('/fetchNewsFromSource', [ApiController::class, 'fetchNewsFromSource'])->name('fetchNewsFromSource');
///Route::post('/sourceId', 'ApiController#displayNews');
Route::get('/', 'App\Http\Controllers\ApiController#displayNews');
Route::post('sourceId', 'App\Http\Controllers\ApiController#displayNews');
Route::middleware(['auth:sanctum', 'verified'])->get('/dashboard', function () {
return view('dashboard');
})->name('dashboard');
`
Dashboard php
<!DOCTYPE html>
<html lang="{{ config('app.locale') }}">
<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>News Application with Laravel</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700" rel="stylesheet" type="text/css">
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div id="appendDivNews">
<nav class="navbar fixed-top navbar-light bg-faded" style="background-color: #e3f2fd;">
<a class="navbar-brand" href="#">News Around the World</a>
</nav>
{{ csrf_field() }}
<section id="content" class="section-dropdown">
<p class="select-header"> Select a news source: </p>
<label class="select">
<select name="news_sources" id="news_sources">
<option value="{{$sourceId}} : {{$sourceName}}">{{$sourceName}}</option>
#foreach ($newsSources as $newsSource)
<option value="{{$newsSource['id']}} : {{$newsSource['name'] }}">{{$newsSource['name']}}</option>
#endforeach
</select>
</label>
<object id="spinner" data="spinner.svg" type="image/svg+xml" hidden></object>
</section>
<div id="news">
<p> News Source : {{$sourceName}} </p>
<section class="news">
#foreach($news as $selectedNews)
<article>
<img src="{{$selectedNews['urlToImage']}}" alt=""/>
<div class="text">
<h1>{{$selectedNews['title']}}</h1>
<p style="font-size: 14px">{{$selectedNews['description']}} <a href="{{$selectedNews['url']}}"
target="_blank">
<small>read more...</small>
</a></p>
<div style="padding-top: 5px;font-size: 12px">
Author: {{$selectedNews['author'] ? : "Unknown" }}</div>
#if($selectedNews['publishedAt'] !== null)
<div style="padding-top: 5px;">Date
Published: {{ Carbon\Carbon::parse($selectedNews['publishedAt'])->format('l jS \\of F Y ') }}</div>
#else
<div style="padding-top: 5px;">Date Published: Unknown</div>
#endif
</div>
</article>
#endforeach
</section>
</div>
</div>
</body>
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<!-- Scripts -->
<script src="{{ asset('js/site.js') }}"></script>
</html>
apicontroller.php supposed to grab from this to get the news api
<?php
namespace App\Http\Controllers;
use App\Models\Api;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
class ApiController extends Controller
{
/**
* #param Request $request
* #return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function displayNews(Request $request)
{
$response = $this->determineMethodHandler($request);
$apiModel = new Api();
$response['news'] = $apiModel->fetchNewsFromSource($response['sourceId']);
$response['newsSources'] = $this->fetchAllNewsSources();
return view('dashboard', $response);
}
/**
* #param $request
* #return mixed
*/
protected function determineMethodHandler($request)
{
if ($request->isMethod('get')) {
$response['sourceName'] = config('app.default_news_source');
$response['sourceId'] = config('app.default_news_source_id');
} else {
$request->validate([
'source' => 'required|string',
]);
$split_input = explode(':', $request->source);
$response['sourceId'] = trim($split_input[0]);
$response['sourceName'] = trim($split_input[1]);
}
return $response;
}
/**
* #return mixed
*/
public function fetchAllNewsSources()
{
$response = Cache::remember('allNewsSources', 22 * 60, function () {
$api = new Api;
return $api->getAllSources();
});
return $response;
}
}
You should pass an array with variables to views
view('dashboard', ["sourceId" => 1, /* and so on */]);
I can't understand what are you doing there.

how to create a function to fetch variables, retrieve them, and access them on the preview page

how to create a function to fetch variables, retrieve them, and access them on the preview page, getting data from a user by the related id in another table?
I need to create a function that looks for the parameter passed by url in the database, more specifically in the table "company", column "name"
the user types company / name in the address bar and laravel should search for this name and find it (if any), with that name in hand, I need it sent to the view page, where it will load bootstrap classes from the personalite table, that is related to the user through the id, I've tried everything, but I don't have much experience
I found this code that does not have much to do with my question, but it was the closest I came, but I didn't copreendi very well, in the end, it didn't work out and I need to finish my project :(
public function retorna_disciplina($id)
{
$prontuario = session('prontuario');
$cargo = session('cargo');
if($cargo == "P")
{
$disciplina = DB::table('oferecimento_disciplina')
->where('id_professor','=', $prontuario)
->where('dsa', '=', $id)
->first();
if(count($disciplina)>0)
{
$postagens = DB::table('postagens')
->where('dsa', '=', $id)
->get();
return view('disciplinas.disciplina')->with([
'disciplina' => $disciplina,
'postagens' => $postagens
]);
}
else{
Redirect::to('/perfil')->withErros("A disciplina não existe ou você não tem permissão de acesso");
}
}
}
I created a route and it seems to work well
Route::get('/company/{name}', "company/index_controller#search_base_home(name)");
I created a model, a controller and 2 views, 1 if the laravel finds the name and another if not (a search page)
my problem is really creating the function, I'm not getting
tell me what i need to do to put this into practice i would be very grateful for the help
There may be something wrong with the code, disagreements or something, sorry if that is the case, just an example for you to understand my question better
Right now I'm trying hard with this here, but nothing, I don't know, doesn't seem to get the url name
$this->validate($request, [
'name' => 'required|unique:company|name',
]);
#if (count($errors) > 0)
<div class="alert alert-danger">
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
the view code is this (companybase_lg.blade.php)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>iofrm</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://brandio.io/envato/iofrm/html/css/fontawesome-all.min.css">
<link rel="stylesheet" type="text/css" href="https://brandio.io/envato/iofrm/html/css/iofrm-style.css">
<link rel="stylesheet" type="text/css" href="https://brandio.io/envato/iofrm/html/css/iofrm-theme1.css">
</head>
<body>
<div class="form-body">
<div class="website-logo">
<a href="index.html">
<div class="logo">
<img class="logo-size" src="images/logo-light.svg" alt=""><!--- db class here --->
</div>
</a>
</div>
<div class="row">
<div class="img-holder"><!--- db class here --->
<div class="bg"></div>
<div class="info-holder">
</div>
</div>
<div class="form-holder"><!--- db class here --->
<div class="form-content">
<div class="form-items">
<h3>Get more things done with Loggin platform.</h3>
<p>Access to the most powerfull tool in the entire design and web industry.</p>
<div class="page-links">
LoginRegister
</div>
<form>
<input class="form-control" type="text" name="username" placeholder="E-mail Address" required><!--- db class here ---><!--- db class here --->
<input class="form-control" type="password" name="password" placeholder="Password" required><!--- db class here --->
<div class="form-button">
<button id="submit" type="submit" class="ibtn">Login</button> <!--- db class here --->
Forget password?
</div>
</form>
<div class="other-links">
<span>Or login with</span>FacebookGoogleLinkedin
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://brandio.io/envato/iofrm/html/js/jquery.min.js"></script>
<script src="https://brandio.io/envato/iofrm/html/https://brandio.io/envato/iofrm/html/js/popper.min.js"></script>
<script src="https://brandio.io/envato/iofrm/html/js/bootstrap.min.js"></script>
<script src="https://brandio.io/envato/iofrm/html/js/main.js"></script>
</body>
</html>
FINAL PART
I tried to get the data to fill in with the classes, but returns nothing related to the name, I don't know if I made a mistake somewhere ...
#foreach($companies as $company)
<div class="{{ $companies->personalite->div_class_1 }}"></div>
<div class="{{ $companies->personalite->div_class_2 }}"></div>
<div class="{{ $companies->personalite->div_class_3 }}"></div>
<div class="{{ $companies->personalite->div_class_4 }}"></div>
#endforeach
so I need to take div_class_1 which is in the personalite table and put in div
each user has their classes in this table and is related to it by an ID number, I created a column "name" in the table to do the test but so far nothing
I don't understand the whole question. But I can answer this part of your question.
Question : I need to create a function that looks for the parameter passed by url in the database, more specifically in the table "company", column "name"
Route
Route::get('companies/{name}', 'CompaniesController#searchByName');
Controller
public class CompaniesController extends Controller
{
public function searchByName($name)
{
$company = Company::where('name', $name)->first();
return view('your_blade_view', compact('company'));
}
}

Always get NULL when getting the selected value from dropdown Laravel

I'm trying to get the selected value from a dropdown in my view through my controller, but it's always returning null. I really don't know why.
Here is my select dropdown:
UPDATED: Here is my full blade view!
#extends('backpack::layout')
#section('header')
<section class="content-header">
<h1>
<span class="text-capitalize">Thành tích tốt nhất ngày</span>
</h1>
<ol class="breadcrumb">
<li>Admin</li>
<li>Thành tích tốt nhất ngày</li>
<li class="active">List</li>
</ol>
</section>
#endsection
#section('content')
<form method="GET">
Lọc round:
<select id="tablefilter" name="tablefilter">
<option value="0">Hiện tại</option>
#foreach($max as $item)
<option value="{{$item->countRound}}">{{$item->countRound}}</option>
#endforeach
</select>
</form>
<table id="currentRound" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>Câu lạc bộ</th>
<th>Quãng đường</th>
<th>Quãng đường trung bình</th>
<th>Xếp hạng</th>
<th>Số thành viên</th>
<th>Ngày xếp hạng</th>
</tr>
</thead>
<tbody>
#foreach ($result as $item)
<tr>
<td>{{$item->name}}</td>
<td align="right">{{number_format($item->total_distance/1000, 2)}} km</td>
<td align="right">{{number_format($item->avg_distance/1000, 2)}} km</td>
<td align="right">{{number_format($item->rank)}}</td>
<td align="right">{{$item->total_member}}</td>
<td>{{$item->created_at}}</td>
</tr>
#endforeach
</tbody>
</table>
<script>
$(document).ready(function () {
$('#currentRound').DataTable({
"paging" : true,
"aaSorting": [[3, 'asc']],
"dom": '<"top"f>rt<"bottom"lp><"clear">',
});
});
</script>
#endsection
#section('after_styles')
<!-- DATA TABLES -->
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.19/css/dataTables.bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<!-- CRUD LIST CONTENT - crud_list_styles stack -->
#stack('crud_list_styles')
#endsection
#section('after_scripts')
<script type="text/javascript" charset="utf8"
src="https://cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" charset="utf8"
src="https://cdn.datatables.net/1.10.18/js/dataTables.bootstrap.min.js"></script>
#endsection
And in my controller:
public function index(Request $request) {
$round = $request->input('tablefilter');
//dd($round);
$mMile = new MilestoneEarth();
$max = $mMile->getRound();
return view('admin.cacheClubEarth.index',['result' => $result, 'max' => $max]);
}
It's return [] with $request->all() and null with $request->tablefilter
I really don't know how to do with this!
Can you help me!
Thank you very much!
You can do : dd(request->all()); for check the data.
I think you don't have to use the input function. Try this :
$round = $request->tablefilter;
you need to send the form value either submit using button or use ajax for it
here the basic submitting data via form (i specified action in case you go to different page)
<form method="GET" action="{{url('/to/index/controller/you-want')}}>
Lọc round:
<select id="tablefilter" name="tablefilter">
<option value="0">Hiện tại</option>
#foreach($max as $item)
<option value="{{$item->countRound}}">{{$item->countRound}}</option>
#endforeach
</select>
<button class="something">Update</button>
</form>
#foreach($max as $item)
<option value="{{$item}}">{{$item}}</option>
#endforeach

Correct view output Laravel

That's my controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Spieler;
class SpielerController extends Controller
{
public function getSpieler(Request $request){
$spielID = $request->get('spielID');
$spielerOutput = Spieler::where('spielPlanID', '=', $spielID)->get();
return view('spieler')->with('alleSpieler', $spielerOutput);
}
}
here you can see my view which I will trigger
#extends('app')
#section('contentSpieler')
<h1>Spieler</h1>
#if(count($alleSpieler) > 0)
#foreach($alleSpieler as $teamSpieler)
{{ $teamSpieler->note }}
#endforeach
#endif
#endsection
And here is my main index/app page
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dateneingabe</title>
<link rel="stylesheet" href="/css/app.css">
<script src="{{ asset('/js/jquery-3.2.1.min.js') }}"></script>
</head>
<body>
<div class="container">
<h1>Spiele und Spieler AJAX - Drop Down</h1>
<div class="col-lg-4">
#yield('contentSpiel')
</div>
<div class="col-lg-4">
#yield('contentSpieler')
</div>
</div>
</body>
</html>
When my controller is going to trigger i get back this in my console
<script src="http://localhost:8000/js/jquery-3.2.1.min.js"></script>
</head>
<body>
<div class="container">
<h1>Spiele und Spieler AJAX - Drop Down</h1>
<div class="col-lg-4"></div>
<div class="col-lg-4">
<h1>Spieler</h1> 2.5 Blasdasd
</div>
</div>
</body>
</html>
But I want only that {{ $teamSpieler->note }} should appear in my index/app page in the part #yield('contentSpieler'). What is wrong with my code? The correct value of note 2.5 is in the html console output but at the moment I don't know why there is no output on my index/app page?
if your master view file location is view->index->app.blade.php then
your view file should be like this
#extends('index.app')
#section('contentSpieler')
<h1>Spieler</h1>
#if(count($alleSpieler) > 0)
#foreach($alleSpieler as $teamSpieler)
{{$teamSpieler->note}}
#endforeach
#endif
#endsection
here your master view file location should be correct to extend it in your view file

Passing variable to view by with not working in laravel 5.1

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="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></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
I can access to $message and $title in home.blade.php , But no in price.blade.php
how can I fix it ?
You have an error in a word - maessage, maybe you sending message, but trying to use maessage. Please check it.
Update:
Your code now looks fine. However, look at #if (empty($prices)) part. If (empty($prices) returns true, your code with $message part will never be executed. Probably that's why you don't see my message text.
Update 2:
return view('home')
->nest('content', 'price', array(
'prices' => $prices,
'title' => 'prices page',
'message' => 'my message text'
))
->with([ 'title' => 'prices page', 'message' => 'my message text']);

Categories