I already started using Laravel and I have this problem
"Symfony\Component\Debug\Exception\FatalThrowableError Class 'app\link' not found".
under the app folder, I have a link file but it's empty and not in PHP format, what I need to do in this case?
If your file is under app folder but it is not in PHP format, you have the answer for your question. Laravel will not recognize it as a class if the file isn't a php file. Just rename is to Link.php and add a basic structure, like this one:
<?php
namespace App;
class Link
{
public function __construct()
{
}
}
Also, check this link and learn how to ask a good question in Stack Overflow.
Hope it helps.
Related
I have created a laravel project with Rims and tyres. when clicking a Rim from the index page, i would like to link directly to a rim detail page, like a productdetails page based on the clicked product.
So far, it seems that my route and blade files are fine! but i have no idea how to make the controller function. i have tried with:
public function show($id)
{
$rimdetails = rimdetails::with('rimdetails')->findOrFail($id);
return View::make('rimdetails', compact($rimdetails));
}
and getting the error :
Class 'App\Http\Controllers\rimdetails' not found
try this one
for laravel 6
Route::get('rims','App\Http\Controllers\RimDetails#show');
for laravel 8
use App\Http\Controllers\RimDetails';
Route::get('rims',[RimDetails#show,'show']);
and also make sure you have exact name of file as you have in controller
You need to alias this rimdetails class if you want to reference it correctly. Currently you are in a declared namespace and referencing a class, rimdetails. PHP thinks you are referring to a class named rimdetails in the current namespace App\Http\Controllers so its looking for App\Http\Controllers\rimdetails as per the error.
Add this below the namespace declaration and before the class definition:
use App\rimdetails;
Assuming your model is in the app folder.
I had anonymous component resources\views\components\homepage\feedback.blade.php to render feedback on homepage. From the beginning it was just html. Then I decided to connect Class file. I already had another View Class component and I just copied it manually instead of using artisan command.
App\View\Components\Feedback.php
namespace App\View\Components;
use Illuminate\View\Component;
use App\Models\Feedback;
class Feedback extends Component
{
public $feedbacks;
public function __construct()
{
$this->feedbacks = Feedback::wherePublished(true)->take(5);
}
public function render()
{
return view('components.homepage.feedback');
}
}
And then {{ dd($feedbacks) }} in view file gives me error that this variable is not defined.
Undefined variable: feedbacks (View: C:\laragon\www\lara7\resources\views\components\homepage\feedback.blade.php)
If I try to create Test component with artisan command and put this code inside it works, but then I cannot rename it back to Feedback class. It gives me error
Symfony\Component\ErrorHandler\Error\FatalError
Cannot declare class App\View\Components\Feedback because the name is already in use
But old class already deleted, so I cannot understand what is wrong.
It seems like there is some hidden link between View Class and Blade components, which needs to be erased. But where is this link located?
When switching component type from anonymous to class and back, you have to clear compiled view files:
php artisan view:clear
That's because Laravel incorporate specific component type invocation into the compiled view code.
I found problem.
I got $feedbacks is undefined, because my anonymous component without variables initially was located in resources\views\components\homepage\feedback.blade.php and when I decide to create View Class for this component there was no link established.
Laravel creates automatic link between feedback.blade.php and app\View\FeedbackComponent.php only when blade file located directly in resources\views\components folder. And my component was in subfolder.
So laravel tried to render resources\views\components\homepage\feedback.blade.php with $feedback variable inside and it cannot find where $feedback is defined.
So I just manually register FeedbacksComponent class like that in appservice provider boot method
Blade::component('homepage-feedbacks', FeedbacksComponent::class);
and then use <x-homepage-feedbacks/> to render it
I would say documentation is not very clear. It says that outside of components folder automatic discovery is not working.
But it doesn't say that inside components subfolder automatic discovery is not working.
In Laravel 8 you can use and no need to declare the component
<x-homepage.feedback />
I think you're right I have been having the same issue and and I've been really struggling with it. Finally I found a workaround which is if you change the file name it works so I think it's a problem with the laravel framework and I think they need to address this issue
I've created a helper file using the following method:
Created file in app/Http/helpers.php
Added file path in composer.json
Run this command: composer dumpautoload
Everything worked well but I want to use my models here so that I don't have to write code for getting data from database every time, but it's giving an error that model class not found.
function productImagePath($image_name) {
$generalSettings = \GeneralSettingsModel::GetGeneralSettings();
return $generalSettings;
}
My requirement is that I want to call some model's functions to get frontend (header/footer) design settings from database. So I've to write that code again and again in each controller. I'm very new in Laravel so if it's not a good approach to use helpers for such things, please guide me how it's possible then.
As your GeneralSettingModel class is in the App namespace you will need to include that:
function productImagePath($image_name)
{
$generalSettings = App\GeneralSettingsModel::GetGeneralSettings();
return $generalSettings;
}
Hope this helps!
I am using Lithium Framework. I am trying to call class into a controller, that class is placed inside libraries folder.... But it is showing this error
Fatal error: Class 'app\libraries\Test' not found in /home/ali.mehdi/AvonTPH/app/controllers/SessionsagentController.php on line 34
In libraries folder I created Test.php having following code.
<?php
namespace app\libraries;
class Test{
public static function getTest(){
return "Hi";
}
}
Also Inside my controller.. I used following using statements:
use app\libraries\Test;
But Why Test Class not found... Am I missing something? Any Help would be appreciated.
As #Matei Mihai has commented, in your app\config\bootstrap\libraries.php add the line Libraries::add('.'), though I'd advise against this (see below).
Be aware that the best practice is to put your classes into a package and not drop them in the libraries folder.
I am using a Facedtector class for my work. I added the class in my Codeigniter libraries folder and just called from my controller class. In my controller I also loaded the class but run time it is showing following error:
An Error Was Encountered
Non-existent class: FaceDetector
Please anyone can help me about this.
Thanks
Add your class file inside you library folder of your main application folder.
And then you can use the auto load function of codeigniter
application/config/autoload.php
at the above location and then you can access the class directly or other way of using this use
$this->load->library('Your_Class_Name', 'Path\to\your\class');
This way you can access your class in codeigniter
You can follow below link for autoload of a class library.
https://ellislab.com/codeigniter/user-guide/general/autoloader.html