Laravel 5 pass variable from controller to view


Netera

I'm new to the php platform and what I'm trying to do is pass a variable from the controller to see if the dropdown is populated with an entry from the database, but everything I've tried doesn't work. I get the following error:

Undefined variable: products_create

I don't understand what I'm doing wrong.

controller

public function create()
{
    $products_create = categories::all(['id', 'category']);

    return View::make('products.create', compact('id', 'category'));
}   

view

{!! Form::label('category', 'Categorie') !!}
{!! Form::select('category', $products_create) !!}
Lukasgeiter

You pass the variable to the view as an associative array:

return View::make('products.create', ['products_create' => $products_create]);

compactis a function that helps you build an array where all keys are the same as variable names. However, you must pass the actual variable name to the function:

return View::make('products.create', compact('products_create'));

Related


Unable to pass variable from controller to view in CodeIgniter

Mohsin: I'm having trouble trying to pass a variable from the controller to the view. I think I've made a mistake somewhere and can't find it since I'm a newbie. My controller method is: public function paymentdetail($order_code) { $this->load->model('

Pass variable from controller to view - Laravel

Porcupine 92 I am trying to pass variables from one view to controller to another. I don't get any errors, but when it gets to the last view, it doesn't show the variable as expected. In the first view, I'm just a name. {{ Form::open(array('route' => 'form', '

Laravel 5: Pass multiple arrays from controller to view

username I just started moving to Laravel 5 from Symfony and I'm wondering how to pass multiple arrays from controller to view. I'm trying to use PHP's compact() function but can't get them right in the view. $users = Users::all(); $projects = Projects::all();

Pass variable from controller to partial view rail

devout I am stuck passing variable value from controller to local controller. I have @skillSetData on @skillSetData with all data from skillsets database from controller: SkillSetsController def skillsetdata @skillSetData = SkillSet.all end The skills bel

Laravel controller doesn't pass variable to view

lemon I've seen YouTube tutorials on Laravel. Here is the code. I am starting to learn Laravel. <?php class Authors_Controller extends BaseController { public $restful = true; public function get_index(){ $view = View::make('authors.index',array('name'

Laravel 5 pass database query from controller to view

stevens I am new to Laravel 5 and MVC framework. I am not able to get the result from the database query and pass it to the blade view. Here is the controller function I need... public function show(Project $project) { $technologies = DB::select('select * from

Pass variable from controller to view - Laravel

Porcupine 92 I am trying to pass variables from one view to controller to another. I don't get any errors, but when it gets to the last view, it doesn't show the variable as expected. In the first view, I'm just a name. {{ Form::open(array('route' => 'form', '

Laravel 5 pass data from Controller to View using AJAX

username I'm having trouble passing data from a controller to a view loaded via Ajax. Below is my code: JS: function editass(id, name, title) { var modal_title = document.getElementById("modal-title"); var modal_name = document.getElementById("

Laravel 5: Pass multiple arrays from controller to view

username I just started moving to Laravel 5 from Symfony and I'm wondering how to pass multiple arrays from controller to view. I'm trying to use PHP's compact() function but can't get them right in the view. $users = Users::all(); $projects = Projects::all();

Pass variable from other controller to view in Laravel 4

Wasswa Samuel I'm building a simple voting application in Laravel 4 where candidates are voted. I have two entities candidate and voting relationship one to one. When someone clicks a button, I'll get the candidate's ID and store it in a poll table with only o

Pass variable from controller to view - Laravel

Porcupine 92 I am trying to pass variables from one view to controller to another. I don't get any errors, but when it gets to the last view, it doesn't show the variable as expected. In the first view, I'm just a name. {{ Form::open(array('route' => 'form', '

Laravel 5 pass variable from controller to view

Netera I'm new to the php platform and what I'm trying to do is pass a variable from the controller to see if the dropdown is populated with an entry from the database, but everything I've tried doesn't work. I get the following error: Undefined variable: prod

Laravel 5 pass database query from controller to view

stevens I am new to Laravel 5 and MVC framework. I am not able to get the result from the database query and pass it to the blade view. Here is the controller function I need... public function show(Project $project) { $technologies = DB::select('select * from

Laravel controller doesn't pass variable to view

lemon I've seen YouTube tutorials on Laravel. Here is the code. I am starting to learn Laravel. <?php class Authors_Controller extends BaseController { public $restful = true; public function get_index(){ $view = View::make('authors.index',array('name'

Laravel 5 pass variable from controller to view

Netera I'm new to the php platform and what I'm trying to do is pass a variable from the controller to see if the dropdown is populated with an entry from the database, but everything I've tried doesn't work. I get the following error: Undefined variable: prod

Laravel controller doesn't pass variable to view

lemon I've seen YouTube tutorials on Laravel. Here is the code. I am starting to learn Laravel. <?php class Authors_Controller extends BaseController { public $restful = true; public function get_index(){ $view = View::make('authors.index',array('name'

Pass variable from controller to view - Laravel

Porcupine 92 I am trying to pass variables from one view to controller to another. I don't get any errors, but when it gets to the last view, it doesn't show the variable as expected. In the first view, I'm just a name. {{ Form::open(array('route' => 'form', '

Laravel 5: Pass multiple arrays from controller to view

username I just started moving to Laravel 5 from Symfony and I'm wondering how to pass multiple arrays from controller to view. I'm trying to use PHP's compact() function but can't get them right in the view. $users = Users::all(); $projects = Projects::all();

Laravel 5 pass data from Controller to View using AJAX

username I'm having trouble passing data from a controller to a view loaded via Ajax. Below is my code: JS: function editass(id, name, title) { var modal_title = document.getElementById("modal-title"); var modal_name = document.getElementById("

Laravel 5 pass data from Controller to View using AJAX

username I'm having trouble passing data from a controller to a view loaded via Ajax. Below is my code: JS: function editass(id, name, title) { var modal_title = document.getElementById("modal-title"); var modal_name = document.getElementById("

Laravel 5 pass variable from controller to view

Netera I'm new to the php platform and what I'm trying to do is pass a variable from the controller to see if the dropdown is populated with an entry from the database, but everything I've tried doesn't work. I get the following error: Undefined variable: prod

Laravel controller doesn't pass variable to view

lemon I've seen YouTube tutorials on Laravel. Here is the code. I am starting to learn Laravel. <?php class Authors_Controller extends BaseController { public $restful = true; public function get_index(){ $view = View::make('authors.index',array('name'