Answer the question
In order to leave comments, you need to log in
How to correctly pass a variable from the controller to the view?
Good evening gentlemen.
I can't bring the variable from the controller to the view.
HTTP error
ERROR 500
Undefined variable: namesite (View: D:\Program\OpenServer\OpenServer\domains\univer-larave.ru\laravel\resources\views\index.blade.php)
Controller with this variable.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class IndexController extends Controller
{
public function index(){
$namesite = 'МУЦА';
//$descsite = 'Данная информация должна быть заменена.';
//return view('index')->with(['namesite'=>$namesite,'descsite'=>$descsite]);
return view('index')->with('namesite',$namesite);
}
}
Answer the question
In order to leave comments, you need to log in
It was in the controller itself :)
I indicated the wrong request path there :(
Example from my controller
public function index()
{
$users = User::orderBy('created_at', 'desc')->paginate(30);
return view('dashboard.pages.users.index', compact('users'));
}
{{ $users }}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class IndexController extends Controller
{
public function index(){
$namesite = 'МУЦА';
//$descsite = 'Данная информация должна быть заменена.';
//return view('index')->with(['namesite'=>$namesite,'descsite'=>$descsite]);
return view('index',['namesite' => $namesite])->with('namesite',$namesite);
}
}
{{ $namesite }}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question