Coder Social home page Coder Social logo

laravel-wp-api's Introduction

laravel-wp-api

Laravel 5 package for the Wordpress JSON REST API

Install

Simply add the following line to your composer.json and run install/update:

"cyberduck/laravel-wp-api": "~1.0"

Configuration

Publish the package config files to configure the location of your Wordpress install:

php artisan vendor:publish

You will also need to add the service provider and optionally the facade alias to your app/config/app.php:

'providers' => array(
  'Cyberduck\LaravelWpApi\LaravelWpApiServiceProvider'
)

'aliases' => array(
  'WpApi' => 'Cyberduck\LaravelWpApi\Facades\WpApi'
),

Usage

The package provides a simplified interface to some of the existing api methods documented here. You can either use the Facade provided or inject the WpApi class.

Posts

WpApi::posts($page);

Pages

WpApi::pages($page);

Post

WpApi::post($slug);

Categories

WpApi::categories();

Tags

WpApi::tags();

Category posts

WpApi::category_posts($slug, $page);

Search

WpApi::search($query, $page);

Archive

WpApi::archive($year, $month, $page);

laravel-wp-api's People

Contributors

simotod avatar threesquared avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

laravel-wp-api's Issues

Laravel 5.2.* - php artisan vendor:publish - error

Hello Cyber-Duck,

I recently ran into an error while trying to install your package.
First off, I'd like to suggest to you to change the order of the steps for installing the package.
I think adding the ServiceProvider and Alias should go before trying to artisan vendor:publish.

The error comes when you try to "php artisan vendor:publish". Artisan echo's "Nothing to publish for tag []."
The Laravel Log shows:
"development.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Call to undefined method Illuminate\Foundation\Application::bindShared()' in J:\PhpstormProjects\peqnew\vendor\cyberduck\laravel-wp-api\src\Cyberduck\LaravelWpApi\LaravelWpApiServiceProvider.php:33".

Seems like the bindShared() method is deprecated and should be replaced with the bind() method adding an extra true or false parameter, as explained by Will Vincent on Laracasts forum:
https://laracasts.com/discuss/channels/laravel/laravel-52x-call-to-undefined-method-illuminatefoundationapplicationbindshared-error?page=1#reply-140221

In the end replacing this code in vendor\cyberduck\laravel-wp-api\src\Cyberduck\LaravelWpApi\LaravelWpApiServiceProvider.php:
`public function register() {
$this->app->bindShared('wp-api', function ($app) {

    $endpoint = $this->app['config']->get('wp-api.endpoint');
        $auth     = $this->app['config']->get('wp-api.auth');
    $client   = $this->app->make('GuzzleHttp\Client');

    return new WpApi($endpoint, $client, $auth);
});

$this->app->bind('Cyberduck\LaravelWpApi\WpApi', function($app) {
    return $app['wp-api'];
    });

}`

with this fixed the problem and I successfully did a vendor:publish:
`public function register() {
$this->app->bind('wp-api', function ($app) {

    $endpoint = $this->app['config']->get('wp-api.endpoint');
        $auth     = $this->app['config']->get('wp-api.auth');
    $client   = $this->app->make('GuzzleHttp\Client');

    return new WpApi($endpoint, $client, $auth);
}, true);

$this->app->bind('Cyberduck\LaravelWpApi\WpApi', function($app) {
    return $app['wp-api'];
    });

}`

Greetings

Wordpress api url changed

I decided to use your plugin to connect a Laravel application to a wordpress application, but when itested it, i realised there was a problem with the wordpress rest-api url you are using.

It seems the url as now change in the newest version of rest-api.

As you can see in the following link, the new url is /wp-json/wp/v2/posts, and the one in your plugin is still what seems to be the previous link : /wp-json/posts/

WP-API/WP-API#1164

I'm not sure if that link could change again, but it could be interesting to change it in your code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.