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/ */
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');
}
}