cannot access Component controller variables inside the component view - laravel

I have been running into this very weird issue with Laravel.
I had a problem where one of my component views was not able to read the variables defined in its class. It was kind of strange because I have several components running in my project and they all worked fine, except for this one.
So I created a fresh Laravel project to test some things out (Wanted to check if the problem was on my end, maybe I somehow messed up the project files).
I created a new component on a blank project using php artisan make:component top_nav
pre function basically is used as print_r which is in helper.php
Then I simply added a sql_data variable to the class component like so:
i tried many thing as much as i can do but still i can't access that variable
also clear cache of view
of laravel
change name of components but still can't work
kindly help me..........

you should
return view('components.top_nav', ['sql_data' => $sql_data]);
you are not passing the variable to the view

composer install
npm install && npm run dev
php artisan optimize
I just copied your screenshots into a new laravel installation and ran it with no problems.
Try setting the public property with a default value:
public $sql_data = 'testing'
If you try the above and still have issues, I'd like to confirm the output of AdminLogin::all().
PS:
TopNav instead of top_nav Class name please.

Related

Laravel can't see existing vendor class after update

I am no longer able to send email from my Laravel app once I updated to v6.10, 6.11. I have not changed any code, nor have I required or removed anything new from composer recently. This appears to be potentially something with the new build of Laravel, as this exact code is functional and sending email on v6.7 and below.
Error msg:
Class 'League\CommonMark\Environment' not found (View: /home/ww/app/vendor/laravel/framework/src/Illuminate/Mail/resources/views/html/footer.blade.php)
{"exception":"[object] (Facade\Ignition\Exceptions\ViewException(code:
0): Class 'League\CommonMark\Environment' not found (View:
/home/ww/app/vendor/laravel/framework/src/Illuminate/Mail/resources/views/html/footer.blade.php)
at
/home/videocyp/app/vendor/laravel/framework/src/Illuminate/Mail/Markdown.php:103)
The line from my footer from my published vendor file that is causing the issue:
{{ Illuminate\Mail\Markdown::parse($slot) }}
Inside the vendor file Markdown.php
use League\CommonMark\Environment;
class Markdown
{
public static function parse($text)
{
$environment = Environment::createCommonMarkEnvironment();
// etc...
}
Looking at League\CommonMark\Environment, I find the class (as does my IDE):
final class Environment implements EnvironmentInterface, ConfigurableEnvironmentInterface { }
I'm beyond my level of understanding here as to why Laravel is unable to see one of its vendor classes.
Anyone able to help?
Turns out this is the result of a significant (slightly breaking) change made to the Laravel build as of v6.10.
Due to a potential XSS vulnerability, it looks like they changed the root parser to League CommonMark. This is causing other issues with existing email published templates due to excess white space being parsed differently in the new CommonMark parser. Bugs are reported here, here, here.
My particular problem was extremely strange, but it is being reported elsewhere in addition to those reported back to Laravel. It was not consistent across my servers, but a complete rebuild (vagrant) solved the issue.
For the others with their previously published email templates showing raw HTML, a re-publish may resolve the issue if lucky and no changes were made to the templates.
Run the following to regenerate the list of all classes that need to be included in your project.
php artisan clear-compiled -o
composer dump-autoload
If still not working, maybe try reinstalling the package.
composer require league/commonmark
What version of Laravel did you upgrade from? Laravel 6.7?

Laravel project not working in cpanel faced error Target class [App\Http\Controllers\fileController] does not exist

Laravel project not working in cpanel faced error Target class [App\Http\Controllers\fileController] does not exist. But project completely running locally without no error.
Error image
route.php
AuthorController.php
Please help me out. Advanced thanks.
The error appears to be straight foward --You are appear to be missing the definition of the FileController and somewhere within your routes files you are calling the controller.
Route::resource('files', 'FilesController');
To fix an issue like this, make sure you had not renamed any of your controllers to a different name or you could simply run artisan
php artisan make:controller FilesController -r
to get past this issue. Also, try and stick to resourceful controllers as the verbs such as "PUT", "PATCH", "GET" etc. make decrease the readability of your code. If you don't with to expose all the method in a resourceful controller within your route you could have something like
Route::resource('files', 'FilesController')->except('index','show');
and so forth.

Fatal:Class Illuminate\Routing\RouteCollection contains 1 abstract method and must therefore be declared abstract or implement the remaining methods

I didn't change any backend code .I dont know it triggers when I hit any url of laravel app it will show this error.I dont know why this happend and also need solution for this .My laravel version in 5.8 and php 7.2
Fatal error : Class Illuminate\Routing\RouteCollection contains 1 abstract method and must therefore be declared abstract or implement the remaining methods C:\xampp\htdocs\pmf\vendor\laravel\framework\src\Illuminate\Routing\RouteCollection.php on line 14 this is file it is saying.
Reinstall or update composer wont solve the problem. In my case, you just need to restart the local development server, because the problem is just temporary.
Just need to restart the local development server.

Composer failing when I use Route::controller() in my routes.php

I'm working on migrating an existing Laravel 3 application over to Laravel 4.1, and routes are kicking my butt right now. Here is the problem I'm having- in the old application we made frequent use of Route::controller() in the routes file. When I bring those entries over to the new application they seem to work, but they cause composer to get nasty.
For example I have this route:
Route::controller('templates', 'AdminTemplatesController');
Which is working as a route. But when I run composer update I get this error:
{"error":{"type":"ReflectionException","message":"Class AdminTemplatesController does not exist","file":"\/vendor\/laravel\/framework\/src\/Illuminate\/Routing\/ControllerInspector.php","line":28}}
I've tried stripping down and using Artisan to create an entirely new controller- same test, same fail.
Any ideas what I'm doing wrong?
Looks like you have to do it in steps:
1) Disable all of your routes
2) Execute composer update and make the process pass, you don't need your routes to do that
3) Reenable the controller route and fix the issue Laravel is having by not finding it, which could be:
Controllers folder not being loaded in composer.json
Namespace not being loaded in composer.json
In all of those cases, you have to be sure that you have your controllers in any of the files of the folder:
vendor/composer
For example, if you have the controllers folder in the autoload->classmap of composer.json, the file will be:
vendor/composer/autoload_classmap.php
Remember that every time you change composer.json, you have to
composer dumpautoload
So it recreates those files.
EDIT:
About your comment, I had similar problem once when my file was printed in command line, was happening because I had:
<?
instead of
<?php
This makes difference for Laravel.
In Laravel 4 you use "Route::resource()". So your example would be Route::resource('templates', 'AdminTemplatesController');
http://laravel.com/docs/controllers#resource-controllers

Laravel ClassLoader trying to load an old version of my model

So a while back I decided to redo one of my models in Laravel completely, but I wanted to hold on to the original copy of the file just in case. So I renamed it to something like MyModel (OLD).php and left it there in the models folder next to the new model.
Now that I understand Laravel a bit better, I realize that wasn't a great idea, but in any case everything seemed to work for months. Then today, I made a minor update (modifying a database query) to one of the functions in my new model and suddenly Laravel is trying to load the old copy of my model. I finally moved the old copy out of the models folder and into a backup folder completely outside of my laravel application, but now Laravel throws the error:
include(pathToMyModels/MyModel (OLD).php): failed to open stream: No such file or directory
referring to this section of ClassLoader.php
/**
* Scope isolated include.
*
* Prevents access to $this/self from included files.
*/
function includeFile($file)
{
include $file;
}
I tried undoing the modification to the model, changing the route and controller function name, clearing laravel's cache, clearing the browser cache, using different browsers, but nothing seems to work except to manually include the model's php file before calling the class it contains. What can I do to get Laravel to automatically recognize my model like it does all the others I have?
Try to clear composer cache and then run composer dump-autoload.
composer clear-cache
composer dump-autoload
if you don't want to run commands then try this one, i think it's solve your problem.
goto your laravel_project_folder\vendor\composer
now open the file autoload_classmap.php and autoload_static.php in your text editor
and find your old/backup file name line
and rename with actual filename and correct their path.
now run your project again and check for the error occurance, i think your problem is solved.
i just knew that my laravel using old controller after 1 hour of debuging. what time waste
i tried accepted answer but still persist
i delete the controller and recreate, now works
copy all the code
delete the controller
make http request to that controller (404)
create file same name
paste in

Resources