Download the PHP package khtet404/wordpress-to-laravel without Composer
On this page you can find all versions of the php package khtet404/wordpress-to-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package wordpress-to-laravel
WordpressToLaravel
You want a blog, right? And you want to use the Wordpress backend? But you dislike Wordpress themes, and REALLY dislike creating them? Then this is for you my friend...
This package provides the tool-set to sync WP posts from the WP DB and into your Laravel DB (or wherever you want it to go). This way you can still use the WP backend to author your posts and manage the backend users etc, but gives you glorious freedom to custom code your own frontend, without the nonsense that is WP themes.
It exposes itself as an Artisan command, which means you can set it up to run on a schedule (using Laravel's scheduler) to sync your WP posts, categories, tags and authors to your Laravel DB.
On to installation...
Install
Via Composer:
After adding the package, add the ServiceProvider to the providers array in config/app.php:
Publish the config file:
Migrate your database to setup the posts, categories, tags & author tables:
Setup the url to your WP blog in your env file:
Finally, we need to configure WP itself. If you're using Wordpress 4.7+, then you're all set - crack on! Otherwise, you'll need to install the WP API plugin to the WP site you wish to sync from:
Usage
Firstly, it's best to perform a full sync to get all your posts etc across in one go. After this it'll only sync page 1 of modified posts (by default).
To force sync all published posts:
The -F
flag forces all posts to be synced. The -T
flag will truncate all the relevant DB tables prior to syncing.
You can rerun that at any time to truncate and resync all your posts etc.
Once that's done, you should setup the following in your Laravel app so that all recently modified WP posts are synced across to the local DB:
Showing Posts
Syncing is only half the job. You'll want to show your posts etc on your blog. But that's super easy too.
Just use the Post, Category & Author Eloquent models that are supplied. Alternatively you can provide your own if you need extra methods or functionality.
For ease I suggest extending from the supplied models. If you want to use your own you should update the config file with your models. Also make sure the transformers work with your model(s) too, otherwise you'll need to supply new versions of those too (they should extend the AbstractTransformer from Fractal), and update the appropriate config value for that models transformer.
Example usage of supplied models (this code would appear in your BlogController, BlogTagController & BlogCategoryController):
Media
When you upload media using the WP backend the links will point to your WP blog url. This might be ok for you. But for us it wasn't. So we installed the S3 plugin on our WP site. This means that all media uploaded via WP will be posted up to your S3 storage, and the URLs to said images will be rewritten on the fly to the S3 location. These updated media urls will be respected when you sync.
Redirecting WP Frontend To New Frontend
Lets say your WP blog is at https://blog.example.com, and your new Laravel frontend is at https://example.com/blog/. Ideally, you'll want your old frontend to redirect to your new frontend. This is simple to achieve by creating a little empty theme and activating it in your WP backend.
- Create new theme in your WP themes dir called 'redirection_theme'
-
Create a file called style.css, and insert the following:
-
Create a file called index.php, and insert the following:
-
Finally, create a file called functions.php, and insert the following:
- Don't forget to activate it in your WP backend.
Enjoy!
Contributing
Please see CONDUCT for details.
Credits
- Lee Overy
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of wordpress-to-laravel with dependencies
cartalyst/tags Version >=v8.0.0
guzzlehttp/guzzle Version ^7.0
illuminate/database Version ^8.0
illuminate/support Version ^8.0
illuminate/console Version ^8.0
illuminate/contracts Version ^8.0
illuminate/events Version ^8.0
league/fractal Version ^0.19.0