I have the error in all migration file
There is an undefined variable in the view template; pass the data correctly to the view
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hola a tod@s: I have a problem, at this moment. I´m working with:
-PHP 8.1.6 (cli) (built: May 11 2022 08:55:59) (ZTS Visual C++ 2019 x64)
-Laravel Framework 9.45.0
But I have a problem during the presentation of the View. ¿Can you give me an opinion about the problem, please.? This is the message. https://shorturl.me/157If3n
Thank you so much.
I have the error in all migration file
There is an undefined variable in the view template; pass the data correctly to the view
@tykus sorry , but I don´t understand your answer. I´m a novice developer in Laravel. Can you explain me with a example.?
Regards
@jestudillo how do you return that view template?
@tykus in my blade ( named "proveedor.blade.php" ) I´m not using a return function. Probably this is my mistake.
@jestudillo there is nothing to return within a view? I was asking how you returned the view (in a Route Closure or Controller action)
You probably need to spend some time learning the basics... https://laracasts.com/series/laravel-8-from-scratch
@tykus thank you so much. in this case I´m working with Route::get ('/provcreate', [ProveedorController::class, 'create'])->name('provcreate');
This is the home page . https://shorturl.me/sEjT If I click the "Registro" Button , appears the error. In this case the URL is http://127.0.0.1:8000/proveedor but it is not working properly.
Did you type localhost:8000/proveedor on the browser?
Please don’t post error messages as screenshots – especially completely illegible ones hosted on sites with spam links.
Instead, copy the error message and paste it into your answer inside a code block. You make a code block by adding a line with three backticks (```) both before and after the code.
@kokoshneta Thank you for your response.
Before the error. https://shorturl.me/sEjT After the error. https://shorturl.me/OWIejCHn
Let me know if this is the best option to show my doubt in order to fix my problem. Regards
@jestudillo That’s still the same screenshot site (or whatever it is). I can’t even see the screenshot, just a mostly blank page with a link that goes to a phishing site. There’s no way to even tell what error you’re getting.
Post the actual error here, not a screenshot.
@kokoshneta the web browser sends me: -ErrorException -PHP 8.1.6 / 9.45.1 -Undefined variable $proveedores
Please check the following link: https://flareapp.io/share/4m4pDbZm#F55
But also in the (Collapse vendor frames) send me several issues. For example:
Illuminate \ Foundation \ Bootstrap \ HandleExceptions : 45 handleError
Illuminate \ Foundation \ Bootstrap \ HandleExceptions : 266 Illuminate\Foundation\Bootstrap{closure}
C:\xampp\htdocs\control_inventario\storage\framework\views\4c3977a812261a5fe93b1d45638d65ba4bb91b18.php : 45 require
Illuminate \ Filesystem \ Filesystem : 109 Illuminate\Filesystem{closure}
@jestudillo Ah, now this we can use!
The ‘several issues’ you see aren’t separate issues – that’s just the stack trace. It’s showing you every step of the code that led to the error, going backwards to the very beginning of the request.
The stack trace looks like you’re running with cached views, though, which isn’t a good idea when developing. Before you try anything else, do this and try reloading both the index route and the proveedor route:
php artisan optimize:clear
If that doesn’t solve it, please copy-paste the following code here (remember to put three backticks ``` on a separate line both before and after each block of code):
routes/web.php file, at least the part of it that defines the index routeDid you pass the variable from the controller correctly? Check if there is a spelling mistake.
@mukeshchand in my Controller, i´m using:
public function index() { $proveedores = proveedores::orderBy('id','desc')->paginate(5); return view('proveedores.index', compact('proveedores')); }
but the error is the same.
== ErrorException == PHP 8.1.6 / 9.45.1 == Undefined variable $proveedores
Also in the "Collapse vendor frames" has more issues.
Thank you so much.
@jestudillo Is your class called proveedores (plural, with a small p)? If so, why? It would be better to call it Proveedor (singular, capital P).
Try this:
route::get('proveedor','MyController@proveedor'); in web.php
public function proveedor( ){$proveedores=proveedores::all();dd($proveedores);} in MyController
use localhost:8000/proveedor and tell us what you see.
@frankhosaka the same error.
Please check the following link. https://flareapp.io/share/LPllz6QP#F55
@jestudillo what does you web.php routes file look like right now? You were visiting http://127.0.0.1:8000/index
earlier, and now http://localhost:8000/proveedor - do you have multiple routes that return that view template?
@tykus it is just one route.
Route::get('/index', function() { return View::make('pages.index'); }); the valid URL is http://127.0.0.1:8000/index
@jestudillo you are not passing anything to the view
@jestudillo but you see that you are doing nothing in the Closure to pass $proveedors to the view template, right?
Route::get('/index', function() {
$proveedores = proveedores::orderBy('id','desc')->paginate(5);
return View::make('pages.index', compact('proveedores'));
});
Make sure you understand how a Request is being handled so you are modifying the correct files
@jestudillo Well, where did you define the variable $Proveedor? Can you add code with code ticks here as suggested before? But the code for the controller used in the view? Two, why does the foreach use the same variable twice? Normally you use
@foreach ($proveedor as $proveedores)
{{ $proveedor->id }} {{ $proveedor->razon_s }} {{ $proveedor->rfc }}
...
@endforeach
@jestudillo wow
@jestudillo See https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks Should help with adding your controller code here at Laracasts with code ticks.
@jestudillo Why not just spend a few hours watching the free Laravel From Scratch course, rather than fumbling in the dark? Such a simple thing as to pass your variable from the controller to the view should not take 27 replies.
@jestudillo i think you passed proveedors as variable.So try @foreach ($proveedors as $proveedor)
Hello amigos. At this moment I have a problem. I´m working with a dynamic droplist down (dependant) but Laravel sends me this error.
Illuminate \ Database \ QueryException PHP 8.1.6 9.45.1 SQLSTATE[42P01]: Undefined table: 7 ERROR: no existe la relación «pais» LINE 1: select "nombre", "id" from "pais" ^
I´m trying to implent the following funcionality in my form.
Droplist 1: Country (País) >> Droplist 2: State (Estado) >> Droplist 3: City (Ciudad)
But it is not working properly. Can you tell me the problem.? Can you help me, please.?
Thank you so much.
@tykus It works. Thank you very much.
Please or to participate in this conversation.