Error while running php artisan serve command on localhost - laravel

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

Related

How to rename a project in Laravel 7

All results from searching the web offer to run the "php artisan app:name {newProjectName} but since Laravel 6 the app:name command has been removed. So what is the way to do it in Laravel 7?
You can rename your project editing the "app.php" at: /laravel-project/config/app.php
/*
|--------------------------------------------------------------------------
| Application Name
|--------------------------------------------------------------------------
|
| This value is the name of your application. This value is used when the
| framework needs to place the application's name in a notification or
| any other location as required by the application or its packages.
|
*/
'name' => env('APP_NAME', 'Laravel'), // "Here your new Project Name"]; ?>
Remove the env('APP_NAME','Laravel') and replace it for your new Project Name
It is recommended to remove the .env and use only the app.php file, or protect the .env file in your .htaccess if your project are in production, there is a possibility to be downloaded from the browser.
See screenshot of the app.php file
Additional Info
After this process please run the following command in your terminal:
php artisan optimize
php artisan config:clear
php artisan config:cache
Rename the App
If you just want to rename your Laravel App you can do so in the .env file and change the APP_NAME
Change the Namespace
Prior to version 6.0 the app:name command allowed to change the application namespace. This feature was removed however, you can read more about it here.
If you really need this feature, there is a community package for version 6, but none for version 7 that I could find.
Create New
From the docs:
laravel new blog
or
composer create-project --prefer-dist laravel/laravel blog
please change name form laravel to your app
'name' => env('APP_NAME', 'Laravel'),
or change config/app.php
'name' => env('APP_NAME', 'Laravel'),
and
php artisan config:cache

Executing config:cache command during deployment

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.

Laravel queue job does not load file in

I am a bit stuck with loading in a file for Laravel Queue/Job
I am using Laravel queued/async jobs (lets call it job for easy use)
Oke lets start from the beginning, we have our own translation function and we also named it __() just like the default from Laravel, don't ask me why etc. (easy solution is to just rename it, I know) but this is what I have to stick with (unless this is unfixable maybe).
So to declare the function before Laravel does we insert the function just before the autoload in the index.php like this.
/*
|--------------------------------------------------------------------------
| 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__.'/../app/Helpers/localization.php'; <-- yes this file
require __DIR__.'/../vendor/autoload.php';
And this works fine for the website and if we execute jobs with SomeJob::dispatchNow() (not async)
But when we want to do a async job like SomeJob::dispatch() the index.php is not called so the file is never required so neither is the function. (or am I wrong?)
I tried it with composer.js autoload
"autoload": {
"psr-4": {
"App\\": "app/"
},
"classmap": [
"database/seeds",
"database/factories"
],
"files": [
"app/Helpers/helpers.php", <-- works fine
"app/Helpers/Localization.php" <-- it does include tho
]
},
now in the file we use the if (! function_exists('__')) but at that point the function is already declared, on the website itself it doesn't work either.
So short saying, require at the index.php only works from the website directly and not from async jobs cause index.php is never called when a queue execute the job.
Using the composer autoload doesn't work for both the website or the job cause the function is already declared by Laravel before we declare it.
So where should I require the file/declare the function so that both the website directly and the async job can use our version of the function.
P.S. I know my english isn't that great, so if anything is unclear or even if I miss any information, please ask me and I try to edit the post to be more clear.
You can add your function definition to the start of the bootstrap file of laravel bootstrap/app.php
Or (since i suspect SomeJob::dispatch() to use artisan), you can require your file in index.php and in artisan
#!/usr/bin/env php
<?php
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 require it
| into the script here so that we do not have to worry about the
| loading of any our classes "manually". Feels great to relax.
|
*/
require __DIR__.'/app/Helpers/localization.php';
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';

Laravel 5.6 - The requested resource /home was not found on this server

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

How to disable log in Laravel 4?

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);
});

Resources