A
A
Archakov Dennis2015-06-09 23:10:22
Laravel
Archakov Dennis, 2015-06-09 23:10:22

How to pass parameters to Laravel template?

In general, there was a problem with passing GET parameters to the template. And to be more precise, the address is: /room/{id}/{meth?}
routes.php

Route::get('/room/{id}/{meth?}', array('as' => 'index', 'uses' => '[email protected]', function ($id, $meth = null) {

    if ( $meth=='delete' ) return 'delete';

}))->where('id', '[0-9a-zA-Z]+');

HomeController
public function Room(){
    return View('room');
  }

room.blade.php
@extends('layouts.default')
{{ $id }}

And the error is this:
ErrorException in 8403e2e5d69462dce318c46b68c17f94 line 1:
Undefined variable: id (View: C:\OpenServer\domains\laravel\resources\views\room.blade.php)

And also, why can't I refer to the class like this: This error happens:
return View::make('room');
FatalErrorException in HomeController.php line 16:
Class 'App\Http\Controllers\View' not found

Thanks in advance for your replies!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
OnYourLips, 2015-06-09
@archakov06

return view('room', '[id' => $id]);

J
JhaoDa, 2015-06-09
@JhaoDa

And where is the passing of the id parameter to the view? Maybe you should read the documentation about templates ?
But first, read the PHP documentation about namespaces.
The View facade is in the global namespace, so it must be referred to as \View.

R
Rikcon, 2015-06-09
@Rikcon

public function Room($id, $meth = null)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question