How to enable laravel debugbar dynamically? - laravel

Is there any way to disable the debugbar by default and enable it dynamically in the middleware?
When in AppServiceProvider boot I add Debugbar::disable(); and then in the middleware in the condition I add Debugbar::enable(); it does not work.
Replacing config('debugbar.enabled') doesn't work either.
Is it possible to do?

Related

Laravel Nova: enable/disable actions log view?

Laravel Nova keeps a log of actions, and can show it like any other resource.
For one of my projects this is somehow enabled, while for a different project (same Nova version) I don't see the Actions under my resources. I'm not sure why.
So how does one enable or disable this view?
Need add trait Actionable to models for enable Action Log.
use Laravel\Nova\Actions\Actionable;
use Actionable;

How to conditionally add middleware in another middleware Laravel

I'm wondering how I can add middleware conditionally in another middleware in my Laravel project.
I noticed that Laravel Nova adds middleware in this way in the NovaCoreServiceProvider
$this->app->make(HttpKernel::class)->pushMiddleware(ServeNova::class);
I am trying to accomplish this outside of the scope of a service provider, where you do not have access to $this->app, so I tried it this way:
$container = app();
$container->make(HttpKernel::class)->pushMiddleware(MyMiddleware::class);
But this doesn't seem to work. Is it possible to push middleware to the stack from a middleware? If so, how can I accomplish this?
The only reason I am doing it this way as opposed to just simply registering it normally is to prevent the unnecessary loading of resources (which the middleware is responsible for triggering).

How do I access a route in Laravel, if Im using https?

Im not sure if my question is valid, I have a laravel app, by default I can access it using http protocol,
but due to security reasons, I was instructed to use https instead,
So I was planning to configure my apache and use the default-ssl.conf,
but before I do that, I want to know if changing it to https will it affect my routes?
No, it will not affect your routes.
To make all helpers like route(), url(), action() etc generate HTTPS links change http to https in the .env file:
APP_URL=https://some.app
It MAY affect your routes !
If you are using cloudflare for your ssl certificate, Laravel will not recognise it as a secure url, You will have to specify in your code that you want a secure url
for example for your assets, you may have to use
secure_asset('img/photo.jpg')
Normal SSH and Cpanel
If you are using normal ssh provided by server providers then do not worry,
You just need to change in your environment file.
which is placed in project_root/.env where you can change your APP_URL from http:// to https://
Also you can directly change in config/app.php in 'url' parameter.
cloudflare
Answer of Mathieu Ferre is correct
if you want to use mixed routes in your application you can use some laravel built-in helper methods.
use secure_asset() and url('url',params, true) the last param in url() is for securing route.
EDIT 1
there is also another function secure_url for securing url. If your application is using mixed routes.
Hope this helps.
Thanks

Laravel 5.3 validation disable

On my project, I did a custom helper like below:
Best practices for custom helpers on Laravel 5
After that, my validations has been disabled. The validations happens normally on server side, withErrors($validator) method, but in my view blade the variable $errors is always empty.
How can I enable the laravel's validation again?
I found a solution here:
http://laravel.io/forum/03-28-2016-errors-variable-empty-after-failed-validation
I finally found a fix, and I want to share it in case anyone else ends up here with the same problem.
In app\Http\Kernel.php I moved \Illuminate\Session\Middleware\StartSession::class from the 'web' $middlewareGroups to $middleware.
I have no idea why this fixed the problem, which worries me a bit. But hey... it's working.

Can Laravel Blade be used in a sandbox environment?

Can Laravel Blade be used in a sandbox environment, similar to Twig's sandbox extension?
I have the need to allow users to use a template system but obviously do not want them executing arbitrary PHP code on the server.
I would like to use Blade since it's already part of Laravel but suspect this isn't possible.
The short answer is no, by default.
You could probably implement this yourself however, by extend blade to add custom functionality. See the Blade Documentation.

Resources