/vendor/autoload.php error while running laravel - laravel

so im new to laravel, just downloaded composer, created new project through terminal in vscode, tried to run it and this error shows up
Error in localhost>public
The Code:
require_once __DIR__ . '/vendor/autoload.php';
and also getting errors while compiling on these:
$response = $kernel->handle(
$request = Request::capture() //Undefined type 'Illuminate\Http\Request'//
)->send();
the illuminate code:
use Illuminate\Http\Request;
Help would be appreciated

You should have following code for autoload.php. Basically, you're trying to look for vendor directory in the public folder, whereas it is normally placed in the base directory
require __DIR__.'/../vendor/autoload.php';

Did you try running a composer update command?

Re-installed everything in the same (C) directory and its working great now
Appreciate the help, thank you, everyone!

Related

PHP Artisan tinker Class 'XdgBaseDir\Xdg' not found

I encountered and error when running php artisan tinker in my current project. I tried to create a new project using laravel new projectname but the same error occurs when running php artisan tinker.
This is the error that occurs.
````Class 'XdgBaseDir\Xdg' not found
````at C:\xampppp\htdocs\someProject\vendor\psy\psysh\src\ConfigPaths.php:34
````30| * #return string[]
````31| */
````32| public static function getConfigDirs()
````33| {
````> 34| $xdg = new Xdg();
````35|
````36| return self::getDirNames($xdg->getConfigDirs());
````37| }
````38|
````1 C:\xampppp\htdocs\someProject\vendor\psy\psysh\src\ConfigPaths.php:90
````Psy\ConfigPaths::getConfigDirs()
````2 C:\xampppp\htdocs\someProject\vendor\psy\psysh\src\Configuration.php:392
````Psy\ConfigPaths::getConfigFiles()
I badly need help. Thank you so much for anyone that knows the solution.
Finally found the solution. I ask my senior if I can copy his vendor files and a composer update followed. What a relief. Thank you still. Peace out!
(Edit)
If you have a working vendor files, you can copy and paste it to the project files folder where you encounter the said error above. Then do a composer update and your all set.
try this one it worked for me probably you don't have the package installed in the vendor
composer require dnoegel/php-xdg-base-dir
I only had to run composer update

How to deploy laravel to server using ftp

Hi I'm newbie on Laravel. I have to upload laravel project to Linux server(CentOS). Customer provide me ftp path. For example 10.222.20.10/srp. So I put all files into that path and after edited database inside .env file. I run 10.222.20.10/srp on webbrowser but I getting error 'This page is not working, error 500'. I attached picture as below. Appreciated for advise and thank you very much.
Please Follow this Steps:
1.
Copy all contents inside the /project/public directory to project/
Remember to copy the public/.htaccess to the project/ also
Now let’s modify the www/index.php to reflect the new structure. Don’t modify the project/public/index.php, okay? Only modify www/index.php, remember this!!!
Find the following line
require __DIR__.’/../bootstrap/autoload.php’;
$app = require_once __DIR__.’/../bootstrap/app.php’;
And update them to the correct paths as following
require __DIR__.’/../project/bootstrap/autoload.php’;
$app = require_once __DIR__.’/../project/bootstrap/app.php’;
2. Set permision 777 project/storage and project/bootstrap/cache
Maybe this tutorial will help you Deploy Laravel To Shared Hosting The Easy Way
Please Follow this Steps:
1.public folder(index.php) is the start point of your application set
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
according to your configuration or use symlink
2.Migrate Database (if you don't have ssh access create a route and use Artisan facade Artisan::call("migrate"); and don't forget to remove it )
3.Link storage if you need (if you don't have ssh access create a route and use Artisan facade Artisan::call("storage:link"); and don't forget to remove it )
4.Check server logs maybe folder premissions is wrong.

How to install package spatie pdf to img in laravel 5.5?

I already install GhostScript and imagick and it's working well in php artisan, now when i install this package Spatie/pdf-to-image it does not have service provider and alias in installation steps. Can you guys help me how to install this package and make it work?
Not Working:
Working in php artisan:
I also try this one and doesn't work:
$pdf = new Spatie\PdfToImage\Pdf('public/test/test.pdf');
$pdf = new \Spatie\PdfToImage\Pdf('public/test/test.pdf');
Here's my composer:
Try again with:
$pdf = new \Spatie\PdfToImage\Pdf('public/test/test.pdf');
Previous error was caused because of wrong namespace. It's better to add Spatie\PdfToImage\Pdf to use section at the top of document and then in code just write $pdf = new Pdf('path/to/pdf');
You first run this command on CMD :
composer require spatie/pdf-to-image
After add this lines in your controller
use Spatie\PdfToImage\Pdf;
$pdf = new Pdf($pathToPdf);
$pdf->saveImage($pathToWhereImageShouldBeStored);

Installing and using Mink with Browserkit driver

I seem to be unable to install Mink with Browserkit driver on Centos.
I am using these instructions: https://github.com/minkphp/MinkBrowserKitDriver
The steps I am taking is by:
adding a file in my project directory with the name composer.json and the contents:
{
"require": {
"behat/mink": "~1.5",
"behat/mink-browserkit-driver": "~1.1"
}
}
Use the commands as below.
$> curl -sS https://getcomposer.org/installer | php
$> php composer.phar install
Now there are 3 files (composer.json, composer.lock, composer.phar) and one folder (vendor) in the project directory. Where do I run the "Usage example" code from (as on the documentation)?
I have tried adding require_once "vendor/autoload.php"; to my test.php file:
<?php
require_once "vendor/autoload.php";
use Behat\Mink\Mink,
Behat\Mink\Session,
Behat\Mink\Driver\BrowserKitDriver;
use Symfony\Component\HttpKernel\Client;
$app = require_once(__DIR__.'/app.php'); // Silex app
$mink = new Mink(array(
'silex' => new Session(new BrowserKitDriver(new Client($app))),
));
$mink->getSession('silex')->getPage()->findLink('Chat')->click();
but getting a fatal error that app.php cannot be opened. I have also tried adding the following to test.php:
require_once 'vendor/behat/mink-browserkit-driver/tests/app.php';
Any help would be appreciated :)
Its seems you're missing some guideline in order to organize your code. Before integrating Behat and Mink, first of all you should organize your Silex project. My advice is for you to take a look at the official Silex Skeleton project.
After that you can start by installing behat, mink and your driver:
cd path/to/your/silex/project/root
composer require behat/behat:~2.5 behat/mink behat/mink-browserkit-driver
Then you can initialize behat.
bin/behat --init
Then configure your mink driver in behat.yml (on your project root directory)
default:
extensions:
Behat\MinkExtension\Extension:
browserkit: ~
base_url: http://my.dev.host
Notice that browser kit cannot execute JS, remember that (if you want to execute JS on your tests, you should install another driver)
After that you can start writing your features on the features directory (behat should've created that for you), for example if you have this controller in src/controllers.php:
<?php
//...
$app->get('/hello', function () use ($app) {
return new Response("Hello world!");
});
You can write the feature (on features/greeting.feature):
Feature: Greetings from /hello page
In order to say hello world
As a visitor
I need to go to the /hello page and see Hello world!
Scenario: See Hello world!
Given I am on "/hello"
Then I should see "Hello world!"
Another option is to use full behat extension for silex: https://github.com/tabbi89/Behat-Silex-Extension
You can check how integrations of Mink and browserKit work there.

Accessing php files out of root folder(Laravel)

Inside my Magento Project folder I want to install laravel so that I can access Mage from laravel. Directory structure is following
Magento(root)
--laravel
--app
...
...
How can I achieve That? Or suggest any other way so that I can access magento from laravel like following.
require_once ('../app/Mage.php');
Mage::app();
Mage::getSingleton('core/session', array('name' => 'frontend'));
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
UPDATE
Controller Location relative to magento
D:\xampp\htdocs\magento\custom\app\controllers\ProductsController.php
Make sure the path is correct, it should work.
Use this one
require_once (realpath(dirname(__FILE__) . '/../app/Mage.php'));
Your path ( require_once ('../app/Mage.php'); ) is not correct that's why you are facing this issue.Except this logic wise your code is correct.
If you are running your code from somefile.php in laravel then it should work.
Magento(root)
--laravel
|__somefile.php
--app
...
...
I have used dirname() function to solve this problem.
require_once (dirname(dirname(dirname(dirname(realpath(__FILE__))))).'/app/Mage.php');
I don't think this the nice or smart way, but it works. Thanks.
Maybe someone useful:
require_once (dirname(dirname(dirname(dirname(realpath(__FILE__))))).'/../app/Mage.php');
\Mage::app();
$blocks = \Mage::getModel('cms/block')->getCollection();
foreach ($blocks as $block) {
echo $block->getTitle()."<br>";
}

Resources