PHP code example of robinmarechal / laravel-rest-api

1. Go to this page and download the library: Download robinmarechal/laravel-rest-api 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/ */

    

robinmarechal / laravel-rest-api example snippets


'providers' => [
    //...
    RobinMarechal\RestApi\RestApiServiceProvider::class,
]



namespace App\Http\Controllers;

// ...
use RobinMarechal\RestApi\Rest\HandleRestRequest;

class Controller extends BaseController
{
	// ...
    use HandleRestRequest;
}



namespace App\Http\Controllers;

// ...
use RobinMarechal\RestApi\Rest\HandleRestRequest;

class Controller extends BaseController
{
	// ...
    use HandleRestRequest;
    
    protected $request;

    function __construct(\Illuminate\Http\Request $request)
    {
        $this->request = $request;
    }
}



namespace App\Http\Controllers\Rest;

class PostsController extends ApiController
{

}


namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    public $timestamps = true;
    protected $fillable = ['title', 'content', 'user_id'];

    
    public function author(){
        return $this->belongsTo('App\User');
    }


    public function comments(){
        return $this->hasMany('App\Comment');
    }
}
bash
php artisan api:table <table_name|model_name> 
                            [--F|fillable=]
                            [--H|hidden=]
                            [--D|dates=]
                            [--T|timestamps=] 
                            [--softDeletes] 
                            [--R|relations=]
                            [--M|migrations]