I came across this code $app['files] in a Laravel package.
I am just wondering what it does in Laravel.
$app['files'] refers to \Illuminate\Filesystem\Filesystem as you can see in the doc here.
It's the same as accessing the File facade but in some places it's better to not use facades and access them with there bindings in the $app var
.
Related
I'm relatively new to Laravel; using 8.26.1
just after creating a project, I noticed that I have RouteServiceProvider.php exists in two locations:
app\providers\ and \vendor\laravel\framework\src\Illuminate\
can someone explain which one should I use to make my changes or guide me to a document where I can read about how and which file is used by Laravel ?
You would be using the one in your application which is everything that isn't in vendor as that is all packages and you should not touch any of that. The App\Providers\RouteServiceProvider (app/Providers/RouteServiceProvider.php) is the provider that is loaded by your configuration in config/app.php. This extends the base one from Laravel to give it the features it needs.
I started with Laravel 7 a few weeks ago. It happened to me multiple times that after reading about a topic on the Laravel website, I wanted to check the details of a function, for example:
Illuminate\Support\Facades\Route::group()
So I went to the Laravel API, and could find the Route facade, but not the group function.
What am I doing wrong? Where do you check for example the exact signature of a function?
Thanks!
The method group in Route::group() is inherited from another class, RegistrarGroup.
See the docblock method in the source file, vendor/laravel/framework/src/Illuminate/Support/Facades/Route.php:
#method static \Illuminate\Routing\Router|\Illuminate\Routing\RouteRegistrar group(\Closure|string|array $attributes, \Closure|string $routes)
so, this is what you look for in the API documentation:
https://laravel.com/api/7.x/Illuminate/Contracts/Routing/Registrar.html#method_group
That is because a Facade, by definition, is only an 'interface' to the methods exponed by another object, so you will not find the actual methods available by visiting the facade code.
Usually you can find the actual class that a facade resolves to (when not mocked) by checking the docblock in the source code and navigate to that class.
A very useful tool to overcome this problem and provide autocompletion (and inspection) for facades on your IDE is the package https://github.com/barryvdh/laravel-ide-helper
I am a happy Laravel user and I love the Laravel helpers.
They are very easy to use:
{{ str_limit($text) }}
But really really don't understand why this is they way:
{{\Illuminate\Support\Str::limit($text)}}
Why...?
The reason for deprecating them in Laravel 5.8 being that they add a
lot of fucntions to the global namespace and in addition to that they
migth conflict withe packages as well. Taylor Otwell has said in the
PR ,
https://techanical-atom.com/laravel-5-8-deprecate-arr-and-str-global-helper-methods/
From the pull request:
They pollute the global namespace and they don't bring any additional value to the framework. They don't even save you the amount of characters that you have to type as in a bunch (or maybe in all?) of cases it's actually shorter to use the Arr and Str methods directly.
https://github.com/laravel/framework/pull/26898
If you still want to use them you can install the laravel/helpers package
I am trying to add the following package to my Laravel 5.2 project. At the top of my class I have added
use PhpImap\Mailbox as ImapMailbox;
use PhpImap\IncomingMail;
use PhpImap\IncomingMailAttachment;
I then do something like this
$mailbox = new ImapMailbox('{imap.gmail.com:993/imap/ssl}INBOX', 'some#gmail.com', '*********', __DIR__);
At the moment, when I visit the page I get
Class 'PhpImap\Mailbox' not found
I have tried many different ways to load it with the same result. Because this package is not Laravel specific, I don't know if I need to add anything else? Normally when I add Laravel packages I create a provider and alias, do I need to do that here?
Any information appreciated.
Thanks
I am implementing Twilio in Laravel 5, the tutorial I am using is very good https://www.twilio.com/blog/2014/09/getting-started-with-twilio-and-the-laravel-framework-for-php.html.
Do you know what the namespace is for laravel 5?
I am getting
Class 'Services_Twilio_Twiml' not found
Thanks
If you install the twilio/sdk package via composer you should have access to all the Twilio classes automatically, since laravel uses composer's autoloading.
They are not really namespaced. You would use \Services_Twilio_Twiml.
You can tell composer to load your Twilio folder by adding :
"autoload" : {
"classmap" : [ "your/Twilio/folder" ]
}
to your composer.json
If I understood you clearly you have put your Twilio code in a given file and you are getting this error saying "Class 'Services_Twilio_Twiml' not found".
I am writing here possible reason you are getting this.
/config/services.php- you have not added Twilio details which are
i. sid
ii. token
iii. from
in file in which you have integrated your Twilio code, you have to ensure to write use Twilio;
In your app.php you have to add in providers section Twilio which you are using for example: 'Aloha\Twilio\TwilioServiceProvider'
and aliases section 'Twilio' => 'Aloha\Twilio\Facades\Twilio',.
If you look at this you might find answer.
For Laravel 5 (and older Laravel 4 applications) I suggest using the aloha/twilio package. It provides some code samples in the readme file that should help you get going quickly. One can inject a configured object using the TwilioInterface type hint which has methods to send SMSs MMs and calls.