将Corcel与Laravel一起使用

时间:2016-10-04 20:00:06

标签: php wordpress laravel

我正在尝试将Corcel与Laravel一起使用,我正在遵循Corcel git上的说明:https://github.com/jgrossi/corcel但是,我遇到了问题。

我对Laravel很新,所以我确信这是我正在做的事情,但这对我来说是一次学习经历,并寻找那些能够指出我正确方向的人。

我遇到的问题是当我到达“所以现在你可以获取数据库数据时”的部分时:“

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

我已尝试过这两种方法,并且每次都会收到错误。

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

那是我使用App \ Post版本的时候。

Class 'Corcel\Post\Post' not found

那时我使用的是Corcel \ Post版本。

我的控制器和Post模型类中也有这个:

use Corcel\Post as Corcel;

我有什么遗失的东西吗?谢谢!

2 个答案:

答案 0 :(得分:0)

使用Laravel 5.4我遇到了完全相同的问题。但是,我设法解决了这个问题。它基于放在Controllers文件夹中的帖子。

应用/ HTTP /控制器/ 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';
}

答案 1 :(得分:0)

确保已相应地设置并配置了corcel。

//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);