I want to make a simple thing: display wordpress posts on my website from sql code. I have done this, which is very bad:
use App\Http\Controllers\Controller;
class WordPressController extends Controller
{
private $datatableName = "www1";
/**
* [collectData description]
*
* @param int $numElements
* @param null $page
* @return
*/
public function collectData($numElements=0, $page=NULL)
{
global $mysqli;
$query = "SELECT post_author, post_date, post_title,
post_content FROM `www1_posts` ORDER BY post_date";
$result = $mysqli->query($query);
while(($post_row = $result->fetch_assoc))
{
//
}
}
/**
* [setDatatableName description]
*
* @param string $datatableName
*/
public function setDatatableName(string $datatableName)
{
$this->datatableName = $datatableName;
}
}
What I want to is map table "www1_posts" from Wordpress with a Model (Post) and a view which I 'll call "book.layout.blade.php"
I don't how to write migration from an existing table. Should I write down all the fields ? Or can I grab the table structure from Migration or a Laravel framework class.