PHP code example of thuanpt / larasitory

1. Go to this page and download the library: Download thuanpt/larasitory 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/ */

    

thuanpt / larasitory example snippets




namespace App\Repositories;

use App\Models\Post;
use Larasitory\Repository\BaseRepository;
use App\Repositories\Contracts\PostRepositoryInterface;

class PostRepository extends BaseRepository implements PostRepositoryInterface
{
    /**
     * Set model database
     *
     * @return mixed|string
     */
    public function model()
    {
        return Post::class;
    }
}



namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind(
            \App\Repositories\Contracts\PostRepositoryInterface::class,
            \App\Repositories\PostRepository::class
        );
    }
}



namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use App\Repositories\Contracts\PostRepositoryInterface;

class PostController extends Controller
{
    /**
     * @var \App\Repositories\PostRepository
     */
    private $postRepository;

    public function __construct(PostRepositoryInterface $postRepository )
    {
        $this->postRepository = $postRepository;
    }

    public function show($id) 
    {
        $user = $this->postRepository->getById($id);

        return response()->json($user);
    }
}