I am developing a Laravel application. Now, I am trying to implement the sitemap for my website using this package, https://github.com/spatie/laravel-sitemap. But when I generate sitemap.xml, no paths are included in the file.
I installed the package running the Composer command
composer require spatie/laravel-sitemap
Then I published the Composer.
php artisan vendor:publish --provider="Spatie\Sitemap\SitemapServiceProvider" --tag=config
In the routes/web.php, I added this.
Route::get('sitemap', function () {
SitemapGenerator::create('http://app.localhost/')->writeToFile('sitemap.xml');
return "Sitemap generated".
});
When I run the code and sitemap.xml is generated. When I opened the sitemap.xml, that is all I found in it.
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
</urlset>
I have many routes in the web.php. What is wrong and how can fix it?
You can manually add other urls like below and when you run it, the links will be added to your sitemap file:
use Spatie\Sitemap\SitemapGenerator;
use Spatie\Sitemap\Tags\Url;
Route::get('sitemap', function () {
SitemapGenerator::create('https://vesicash.com/')->getSitemap()
->add(Url::create('/link1')->setPriority(0.5))
->add(Url::create('/link2')->setPriority(0.5))
->add(Url::create('/link3')->setPriority(0.5))
->add(Url::create('/privacy')->setPriority(0.5))
->writeToFile('sitemap.xml');
return "Sitemap Generated";
});
This is how I solved this problem:
I just made sure that the APP_URL was set properly in .env file.
I added, for example: https://example.com/ and boom it worked.
This should also work on your local pc as well.
When I did it first time it looked same for me.
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
</urlset>
I think you did it on your local pc.
So first, you can test with this url.
SitemapGenerator::create("https://spatie.be/en")
->writeToFile(public_path('sitemap.xml'));
If it works well, then I believe it will work on server too.
In my case it worked on server, while it was same result with you on my local.
Related
I got an error with Laravel framework after upgrade from v7 to v8 routes contains parameters on the middle of path like below example doesn’t working on server (Linux OS), But works on local env (macOS)
Route::put('resources/{id}/publish', 'ResourceController#publish');
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>InvalidArgument</Code>
<Message>Unsupported Authorization Type</Message>
<ArgumentName>Authorization</ArgumentName>
<ArgumentValue>Bearer token</ArgumentValue>
<RequestId>someid</RequestId>
<HostId>somehash</HostId>
</Error>
When move the parameter at the end of route it works on both.
Route::put('resources/publish/{id}', 'ResourceController#publish');
Update
Route group begin with:
Route::resource('resources', 'ResourceController', ['index', 'store', 'show', 'update', 'destroy']);
Any help will be appreciated,
Thanks in advance!
Got the reason of this error and it doesn’t related to neither Laravel nor JWT-Auth,
It was nginx config with wrong location matching pattern to proxy_pass to S3.
So this resources/{id}/publish route matches wrongly with S3 proxy_pass and error thrown from S3 not laravel.
Had this working but just updated my website on the server and it seems to have made all my uploaded files head to my public folder in my project rather than the public_html. Any idea on which file i must have uploaded and the fix?
You said you had it working before.
Was that on the same server...live?
If so, then could that be a server issue and not necessarily laravel issue?
Maybe you should ask your host for help and clarifications about what changed?
If you are convinced it was about what you changed...then care to show us?
Ideally if the server is cpanel, you will want to upload all your laravel files into your home's directly...then all your /public folder content into public_html
It will look like this:
.cpanel/
app/
etc/
bootstrap/
mail/
public_html/
content from your laravel /public directory
vendor/
...etc
You also need to go into your /public_html and edit the index.php content:
require __DIR__.’/../vendor/autoload.php’;
$app = require_once __DIR__.’/../bootstrap/app.php’;
And make sure it points to the correct location of your bootstrap folder..if you follow the structure above, then its ok.
Lastly, confirm that your PHP is indeed >= PHP7.0
With help from this answer: https://stackoverflow.com/a/50261573/3475551
I managed to get laravel to save uploaded files to my servers public directory instead of app/public.
Edit app/Providers/AppServiceProvider.php like this:
public function register()
{
$this->app->bind('path.public', function() {
return realpath(base_path().'/../../public_html');
});
}
Hope this helps.
I have simple question on Laravel 5.1. I have created a controller using php artisan command:
php artisan make:controller PageSettings
However it was mistake, because I really wanted to create this controller in Admin folder like this:
php artisan make:controller Admin/PageSettings
Now I want to get rid of my old PageSettings controller. Is it ok just to delete my old PageSettings.php manualy? Or there is something more what needs to be done?
If you only created it and found that you did it wrong, you can manually remove the file and that's it. However when you already added routes to this controller in routes.php you should remove them from routes.php file or alter the file to reflect your new controller.
It is OK to manually delete controller. Just check routes.php if you have some route to that controller and delete it also.
I had an issue with just deleting the file. I tried running my PHPUnit test suite and got an error that looked like this:
Warning: include(): Failed opening '/user/home/me/some/file.php' for inclusion (include_path='.:') in /usr/home/me/some/vendor/composer/ClassLoader.php on line 444
I had to run composer update then composer dump-autoload. After that, everything worked just fine.
Yeah, you can delete manually without tension.
I will suggest you for avoiding more mistakes, you "phpStrom" software, from using this, if you delete manually any file from by click right of mouse->Refactor->safe delete then before deleting they will give all places which were using your file. by clicking "do refactor" you can delete it.
I have installed latest version of Megento 2, everything is working fine frontend, backend and functionality.
I have one issue with bin/magento setup:upgrade command, when I run this command in terminal I get below exception .
[InvalidArgumentException]
There are no commands defined in the "setup" namespace.
Screenshot :
Is there any thing I missed during installation or I need to install some package to let it working?
Please mention setup_version in your module.xml file.
Your module.xml file looks like:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="Vendor_Module" setup_version="1.0.0"/>
</config>
You need to give full permission to both var and pub folders recursively.
sudo chmod -R 777 var pub
Giving full control (read/write/execute) to var and pub directory should solve this issue.
sudo chmod -R 777 var pub
You may also try running the command using sudo.
sudo php bin/magento setup:upgrade
I wanted to add an answer because the others doens't cover all the problems that could generate this error :
There are no commands defined in the "setup" namespace.
in general.
This error could be caused by permission as said in others answer but we could have other scenario.
The absense of : etc/module.xml
An error in /etc/module.xml or in /etc/di.xml or others xml extensions under /etc
If you know other scenario please comment this answer.
Hope this help.
Just remove all the directory of var and remove pub/static directory , it will work bin/magento setup:upgrade
I encounterd the same error while running commands related to magento. I was missing double_quotes(") in module.xml file of the custom module. So check module.xml file for any typos and setup_version.
I want to add one more hint check the 'MAGE_MODE' value in env.php it should be correctly set.
The reason for this error can be seen in the command output: php -f bin/magento.
This will work for most errors like There are no commands defined in the "..." namespace..
A fairly common cause is an error in the VendorName/ModuleName/etc/config.xml.
simple RUN php bin/magento this will show you details where it is broken
I have an existing website up and running, and now I want to add a REST interface to it in an api subdirectory. I'm not able to get this to work with versioning. I installed like so (no errors):
$ php ~/bin/composer.phar create-project laravel/database --prefer-dist api
$ cd api
$ php ~/bin/composer.phar require restler/framework 3.0.0-RC6
Then I uncommented the lines in public/index.php related to Restler and add a new API class that just echos a string. If I run this via php artisan serve and look at it through the localhost URL, then the method works.
Now I want to enable versioning, so I added these lines to public/index.php
use Luracast\Restler\Defaults;
Defaults::$useUrlBasedVersioning = true;
And in app/controllers I created a v1 directory and moved Test.php into that. I also added a namespace directive to the file of the format namespace A\B\v1
When I restart the artisan server and query the API, I get a 404 error. I've tried as both http://localhost:8000/Test and http://localhost:8000/v1/Test
What have I forgotten to do?
Here is how I made it to work. Note the folder where I placed the api class file.
in index.php
use Luracast\Restler\Restler;
use Luracast\Restler\Defaults;
Defaults::$useUrlBasedVersioning = true;
$r = new Restler();
$r->addAPIClass('A\B\Test');
Test.php kept in app/controllers/A/B/v1/Test.php
<?php namespace A\B\v1;
class Test
{
public function get()
{
return 'working';
}
}
Both http://localhost:8000/v1/test and http://localhost:8000/test return "working"