PHP code example of mccool / laravel-auto-presenter
1. Go to this page and download the library: Download mccool/laravel-auto-presenter 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/ */
use Example\Accounts\User;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
protected $table = 'posts';
protected $fillable = ['author_id', 'title', 'content', 'published_at'];
public function author()
{
return $this->belongsTo(User::class, 'author_id');
}
}
use Example\Accounts\Post;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\View;
class PostsController extends Controller
{
public function getIndex()
{
$posts = Post::all();
return View::make('posts.index', compact('posts'));
}
}
use Carbon\Carbon;
use Example\Accounts\Post;
use McCool\LaravelAutoPresenter\BasePresenter;
class PostPresenter extends BasePresenter
{
public function published_at()
{
$published = $this->wrappedObject->published_at;
return Carbon::createFromFormat('Y-m-d H:i:s', $published)
->toFormattedDateString();
}
}
use Example\Accounts\User;
use Example\Blog\PostPresenter;
use McCool\LaravelAutoPresenter\HasPresenter;
use Illuminate\Database\Eloquent\Model;
class Post extends Model implements HasPresenter
{
protected $table = 'posts';
protected $fillable = ['author_id', 'title', 'content', 'published_at'];
public function author()
{
return $this->belongsTo(User::class, 'author_id');
}
public function getPresenterClass()
{
return PostPresenter::class;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.