Ok, in laravel 4, if I want to add my own custom class, eg : library\myFunction.php then I do the following steps :
<?php
$FmyFunctions1 = new myFunctions;
$is_ok1=($FmyFunctions1->is_ok());
?>
<?php namespace App\library {
class myFunctions {
public function is_ok() {
return 'myFunction is OK';
}
}
}
?>
And it works.
But how to do so in Laravel 5 ???
PS : I read What are the best practices and best places for laravel 4 helpers or basic functions?
And tried to add "app/library/", to the autoload array and run composer dum-autoload , but it keeps give me error :
FatalErrorException in xxxx line xx: Class 'myFunctions' not found
I'm also already trying to use :
composer update
composer dump-autoload
php artisan dump
php artisan clear-compiled
php artisan dump-autoload
php artisan optimize
php artisan route:clear
php artisan route:scan
php artisan route:list
But still doesn't work...
The namespace is App\Classes so any class in the Classes directory is available under App\Classes namespace.
Introduction. Laravel's events provide a simple observer pattern implementation, allowing you to subscribe and listen for various events that occur within your application. Event classes are typically stored in the app/Events directory, while their listeners are stored in app/Listeners .
Using the ::class keyword in Laravel Since PHP 5.5 the class keyword is used for class name resolution. This means it returns the fully qualified ClassName. This is extremely useful when you have namespaces, because the namespace is part of the returned name.
This should help you.
FYI: Basically, you could create another directory within app, and then namespace your files in there as appropriate:
app/CustomStuff/CustomDirectory/SomeClass.php.
Then, within your SomeClass.php, make sure you namespace it:
<?php
namespace App\CustomStuff\CustomDirectory;
class Someclass {}
Now, you can access this class using the namespace within your classes:
use App\CustomStuff\CustomDirectory\SomeClass;
After some trial and error, I found the answer.
There is no need to modify Composer. Just modify the Blade into:
<?php
$FmyFunctions1 = new \App\library\myFunctions;
$is_ok = ($FmyFunctions1->is_ok());
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With