How to disable logging in Laravel4.
In codeigniter there is a config like below where we can disable the entire logging itself. Is there any configuration in laravel4 where we can disable it to gain the performance.
$config['log_threshold'] = 0; // <--------- zero to disable logging
Update: This is for Laravel 4.2
Looking at Laravel Error documentation:
You can disable the log by commenting two lines in your app/start/global.php:
/*
|--------------------------------------------------------------------------
| Application Error Logger
|--------------------------------------------------------------------------
|
| Here we will configure the error logger setup for the application which
| is built on top of the wonderful Monolog library. By default we will
| build a basic log file setup which creates a single file for logs.
|
*/
// Log::useFiles(storage_path().'/logs/laravel.log');
and
App::error(function(Exception $exception, $code)
{
// Log::error($exception);
});
Related
I have a secret test key for a payment gateway in the .env file.
APP_TIMEZONE = 'Africa/Lagos'
APP_PAYSTACK_KEY = sk_test_b6c0b4925403blablabla
Reason is that other people working on the project can use their own test key if they have. So in a payment controller i get the value of this key like so:
"authorization: Bearer " .env('APP_PAYSTACK_KEY' , 'sk_test_b6c0b4925403blablabla')
During deployment I intend running config:cache so that Laravel won't be going a long trip in getting the required configuration setups. But from Laravel documentation :
If you execute the config:cache command during your deployment
process, you should be sure that you are only calling the env
function from within your configuration files. Once the configuration
has been cached, the .env file will not be loaded and all calls to
the env function will return null.
So my question is how can I set this APP_PAYSTACK_KEY in the config file and how to retrieve it anywhere in my app?
You can add paystack to your config/services.php file:
<?php
return [
/*
|--------------------------------------------------------------------------
| Third Party Services
|--------------------------------------------------------------------------
|
| This file is for storing the credentials for third party services such
| as Stripe, Mailgun, SparkPost and others. This file provides a sane
| default location for this type of information, allowing packages
| to have a conventional place to find your various credentials.
|
*/
// ...
'paystack' => [
'key' => env('APP_PAYSTACK_KEY', 'sk_test_b6c0b4925403blablabla'),
],
];
Then call config() helper method instead of env() on your controller:
"authorization: Bearer " .config('services.paystack.key')
Now you're safe to cache your configs via calling php artisan config:cache.
I am having issues with php artisan serve command. I am working on one Laravel project and when I access the folder from browser it is working fine but when I run the php artisan serve command it shows me the following error:
Warning:
require(E:\xampp\htdocs\www\LFS\public../vendor/autoload.php): failed
to open stream: No such file or directory in
E:\xampp\htdocs\www\LFS\public\index.php on line 24
Fatal error: require(): Failed opening required 'E:\xampp\htdocs\www\LFS\public../vendor/autoload.php'
(include_path='E:\xampp\php\PEAR') in
E:\xampp\htdocs\www\LFS\public\index.php on line 24
I am new to Laravel please let me know where I am going wrong.
I have checked the code in the public/index.php file below is my code. I guess everything is fine I just copy-paste the same index.php file on my root folder.
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* #package Laravel
* #author Taylor Otwell <taylor#laravel.com>
*/
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__.'../vendor/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'../bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
I want that the project can be directly accessible from the browser and should also run on the php artisan serve command.
In your project folder, the vendor folder is missing so you got this error:
Warning:
require(E:\xampp\htdocs\www\LFS\public../vendor/autoload.php): failed
to open stream: No such file or directory
Just run this command:
composer update --no-scripts
composer update
With this command, you will re-create the vendor folder in your project
i am new in Laravel and now i have to create a custom access log for tracking user activity and it's information like ,IP name and operation performed by the user. if anyone know please help me ,thanks in advance.
In laravel you can find a config file app.php in config/app.php path open this file and find this configuration for logs.
/*
|--------------------------------------------------------------------------
| Logging Configuration
|--------------------------------------------------------------------------
|
| Here you may configure the log settings for your application. Out of
| the box, Laravel uses the Monolog PHP logging library. This gives
| you a variety of powerful log handlers / formatters to utilize.
|
| Available Settings: "single", "daily", "syslog", "errorlog"
|
*/
'log' => env('APP_LOG', 'single'),
'log_level' => env('APP_LOG_LEVEL', 'debug'),
In laravel there are four default settings for logging.
In your case you can change this single to daily
Also you can add this into your .env file
APP_LOG=daily
For more info Check Here
I am having a bit of an issue with one route (and only with this one, every other route works without any issue).
This are my routes (I commented out all routes, except the /home, just to be sure that they are not messing up something):
<?php
// Route::get('/', 'DashboardController#index')->middleware('menu.admin')->name('home');
Route::get('/home', 'DashboardController#index')->middleware('menu.admin')->name('home');
// Route::get('/user/verify/{token}', 'Auth\RegisterController#verifyUser');
// Route::get('logout', '\App\Http\Controllers\Auth\LoginController#logout');
// Auth::routes();
// // Admin routes (admin dashboard)
// require(base_path() . '/routes/admin.php');
// // Site routes (frontend)
// require(base_path() . '/routes/front.php');
I am getting this error:
Not Found
The requested resource /home was not found on this server.
The / route works without any issues, and when I try /home (the only difference between this two routes), I am getting the error.
I did php artisan route:clear, and it didn't help. Does anyone have an idea what is going on (.htaccess file is not an issue here)?
Laravel ^5.6
if your routes are defined properly, and by properly i mean you defineded routes in the right order (to avoid conflicts) and the artisan command php artisan route:list get executed correctly BUT you still get 404 Not found - The requested resource /path was not found on this server. weird, not exactly what you were expecting!!
...i also faced this problem, and here is the thing, that error occurs when you create a folder in the public directory with the same URI
...to illustrate here's an example (this is the problem i faced)
routes/web.php
/*
|--------------------------------------------------------------------------
| Web Routes - Backend
|--------------------------------------------------------------------------
*/
Route::group(['namespace' => 'Backend', 'prefix' => 'backend'], function () {
Route::get('/', 'DashboardController')->name('backend.dashboard');
// ...
});
php artisan route:list
php artisan route:list --name=backend --columns=uri --columns=name
+--------------------------------+--------------------------------------+
| URI | Name |
+--------------------------------+--------------------------------------+
| backend | backend.dashboard |
| // ... | // ... |
+--------------------------------+--------------------------------------+
public/
+---public
| +---backend
| | +---css
| | +---fonts
| | +---images
| | +---js
| +---.htaccess
| +---favicon.ico
| +---index.php
| +---mix-manifest.json
| +---robots.txt
As you can see, i have a route URI that start with backend AND also a folder under the public directory named backend as well, that's what cause the problem, so it's up to you to change one of those, personally i changed the name of the folder under public directory to "back-end". that solved my problem.
you use apache or nginx as web server?
try to set config for webserver
https://laravel.com/docs/5.6/installation
Because, you have a folder named control on /public folder. That error occurs when you create a folder in the public folder with the same name as your route so please change the name of the folder you have put in the public folder so that it has a different name from your route this will probably solve your error
I am attempting to use normal JavaScript with NPM and WebPack.
webpack.mix.js
let mix = require('laravel-mix');
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
mix.js(['resources/assets/js/app
.js'], 'public/js').version()
.sass('resources/assets/sass/app.scss', 'public/css').version();
In my app.js I added a simple test function:
var sayHi = function sayHi()
{
alert('hi');
};
And I included it in a HTML page, and called
<script>
sayHi();
</script>
However, I receive the error:
Uncaught ReferenceError: sayHi is not defined
I believe that WebPack etc. hides it all from the global namespace. I have ensured the compiled JavaScript with npm run watch has been included.
I am looking for insight on how to proceed.