2

I am attempting to use Corcel with Laravel and I am following the instructions that are on the Corcel git: https://github.com/jgrossi/corcel But, am having issues.

I am pretty new to Laravel, so I am certain it's something I am doing, but this is a learning experience for me and looking for those who may be able to point me in the right direction.

The problem I am having is when I get to the portion where it says "So, now you can fetch database data:"

$posts = App\Post::all(); // using the 'wordpress' connection
$posts = Corcel\Post::all(); // using the 'default' Laravel connection

I've tried both of those, and get the errors each time.

Class 'myNameSpace\Http\Controllers\App\Post' not found

That is when I use the App\Post version.

Class 'Corcel\Post\Post' not found

That is when I use the Corcel\Post version.

I also have this in my controller and the Post model class:

use Corcel\Post as Corcel;

Is there something that I am missing? Thank you!

1
  • 1
    Try these at the top: use App\Post;, use Corcel;, then call them with $posts = Post::all(); and $posts = Corcel\Post::all(); Commented Oct 4, 2016 at 20:59

2 Answers 2

1

I was having exactly the same issues using Laravel 5.4. However, I managed to sort it out. It is based on the posts being placed in the Controllers folder.

app/Http/Controllers/Post.php

<?php
namespace App\Http\Controllers;

// Usage $posts = Post::all(); // using the 'wordpress' connection

use Corcel\Model\Post as Corcel;

class Post extends Corcel
{
    protected $connection = 'wordpress';
}
Sign up to request clarification or add additional context in comments.

Comments

0

Make sure you've setup and configured corcel accordingly.

//This goes into your App\Post

namespace App;
    
use Corcel\Model\Post as Corcel;
     
class Post extends Corcel
{
  protected $connection = 'wordpress';
}

//You can now start to get what you need from the WordPress database  in you App\Http\Controllers\PostController like so.

$posts = Post::published()->take(10)->get();
return view('post')->with('post', $post);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.