1. Go to this page and download the library: Download laraish-maintain/laraish library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
laraish-maintain / laraish example snippets
use App\Http\Controllers\Wp\Home;
use App\Http\Controllers\Wp\Page;
use App\Http\Controllers\Wp\Post;
use App\Http\Controllers\Wp\NotFound;
use Laraish\Support\Facades\WpRoute;
// Regular post pages
WpRoute::post('post', [Post::class, 'index']);
// Post pages where post-type is 'movie'
WpRoute::post('movie', [Post::class, 'index']);
// The archive page of "movie" post type.
WpRoute::postArchive('movie', [Home::class, 'index']);
// The child page "works" of the "about" page.
WpRoute::page('about.works', [Page::class, 'index']);
// Any child pages of the "about" page.
WpRoute::page('about.*', [Page::class, 'index']);
// Any descendant pages of the "about" page.
WpRoute::page('about.**', [Page::class, 'index']);
// The "about" page ("about" is the slug of the page)
WpRoute::page('about', [Page::class, 'index']);
// The archive page of "foobar" term of "category" taxonomy.
WpRoute::taxonomy('category.foobar', [Home::class, 'index']);
// The archive page of "category" taxonomy.
WpRoute::taxonomy('category', [Home::class, 'index']);
// The archive page of author "jack".
WpRoute::author('jack', [Home::class, 'index']);
// The archive page for all authors.
WpRoute::author([Home::class, 'index']);
// The search result page
WpRoute::search([Home::class, 'index']);
// All pages
WpRoute::page([Page::class, 'index']);
// The home/front page.
WpRoute::home([Home::class, 'index']);
// All archive pages.
WpRoute::archive([Home::class, 'index']);
// The 404 page.
WpRoute::notFound([NotFound::class, 'index']);
use App\Http\Controllers\Wp\Page;
use Laraish\Support\Facades\WpRoute;
WpRoute::page([Page::class, 'index']);
WpRoute::page('works', [Page::class, 'works']);
use App\Http\Controllers\Wp\Home;
use App\Http\Controllers\Wp\Page;
use Laraish\Support\Facades\WpRoute;
WpRoute::home([Home::class, 'index']);
WpRoute::page([Page::class, 'index']);
// Fallback to auto discovery routing.
WpRoute::autoDiscovery();
use App\Http\Controllers\Wp\Page;
use Laraish\Support\Facades\WpRoute;
WpRoute::page([Page::class, 'index']);
namespace App\Http\Controllers\Wp;
use App\Http\Controllers\Controller;
class Page extends Controller
{
public function index()
{
$data = [ 'foo' => 'bar' ];
// Let Laraish figure out the view file.
// 'wp.page' is the default view if no matched view found.
return $this->resolveView('wp.page', $data);
}
}
use Illuminate\Support\Facades\Route;
// This will use the original UriValidator of Laravel.
Route::get('/my/endpoint', function () {
return 'Magic!';
});
namespace App\Http\Controllers\Wp;
use App\Http\Controllers\Controller;
use App\Models\Post;
class Archive extends Controller
{
public function index()
{
$data = [
'posts' => Post::queriedPosts() // get the posts for current page
];
return $this->view('wp.archive', $data);
}
}
namespace App\Models;
use Laraish\Support\Wp\Model\Post as BaseModel;
class Post extends BaseModel
{
protected $visible = [
'title',
'thumbnail',
'content'
];
}
foreach($posts as $post): setup_the_post( $post->wpPost );
namespace App\Providers;
use Laraish\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* Register the WordPress actions
* @var array
*/
protected $action = [
'pre_get_posts' => 'App\Listeners\MainQueryListener'
];
/**
* Register the WordPress filters
* @var array
*/
protected $filter = [];
}
use App\Models\Post;
$posts = Post::queriedPosts();
use App\Models\Post;
$post = new Post(123);
// As with the `Post` model, these models works the same way.
// `Laraish\Support\Wp\Model\User`
// `Laraish\Support\Wp\Model\Term`
// This make it call the magic method to get the value of the custom field `foobar`.
$foobar = $post->foobar;