A package that helps to group methods that mostly use for the view presentation purpose.

Overview

Laravel Presenter

A package that helps to group methods that mostly use for the view presentation purpose.

Installation

Require the package using composer:

composer require touhidurabir/laravel-presenter

To publish the config file:

php artisan vendor:publish --provider="Touhidurabir\Presenter\PresenterServiceProvider" --tag=config

Configurations

Check the published config file for the details of configurations options.

Usage

First step is to generate a presenter class . To make this process easy, this package comes with a command that helps to generate the presenter classes. To generate the presenter class via command, do as

php artisan make:presenter PresenterClassName

For example :

php artisan make:presenter UserPresenter

will generate a UserPresenter at the App\Presenters namespaced path.

it will have following content

namespace Touhidurabir\Presenter\Tests\App\Presenters;

use Touhidurabir\Presenter\BasePresenter;

class UserPresenter extends BasePresenter {

}

Now to use this with the combination of User model class, drop the HasPresenter trait and defined property $presenter as :

use Illuminate\Database\Eloquent\Model;
use Touhidurabir\Presenter\HasPresenter;
use Touhidurabir\Presenter\Tests\App\Presenters\UserPresenter;

class User extends Model {

    use HasPresenter;

    protected $presenter = UserPresenter::class;
}

And Now any public method defined in the UserPresenter class can be accesses as :

$user->present()->someMethod

It is also possible to not define the $presenter property while using the presenter class for models . In that case it will try to resolve the presenter through the model name and defaule store namespace defined in the config file .

For example, by default it will try to find a class in the App\Presenters location with name of UserPresenter for User model if the $presenter property not set in the User model. If it can find it, then it will use that for User model presenter . If none found, it will throw exception.

It is also possible to set/update the presenter on fly . To do that , need to user the setPresenter method defined in the HasPresenter trait as :

$user->setPresenter(UserPresenter::class);
$user->present()->anyMethodDefinedInPresenter;

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

You might also like...
This package provides convenient methods for making token code, sending and verifying mobile phone verification requests.
This package provides convenient methods for making token code, sending and verifying mobile phone verification requests.

Laravel Mobile Verification Introduction Many web applications require users to verify their mobile phone numbers before using the application. Rather

An opinionated support package for Laravel, that provides flexible and reusable helper methods and traits for commonly used functionality.

Support An opinionated support package for Laravel, that provides flexible and reusable helper methods and traits for commonly used functionality. Ins

Stash view is a composer package for Laravel which caches views using Russian Doll Caching methodology.
Stash view is a composer package for Laravel which caches views using Russian Doll Caching methodology.

Stash View Stash view is a composer package for Laravel which caches views using Russian Doll Caching methodology. What is Russian Doll Caching ? It i

27Laracurl Laravel wrapper package for PHP cURL class that provides OOP interface to cURL. [10/27/2015] View Details

Laracurl Laravel cURL Wrapper for Andreas Lutro's OOP cURL Class Installation To install the package, simply add the following to your Laravel install

This package provides a Logs page that allows you to view your Laravel log files in a simple UI
This package provides a Logs page that allows you to view your Laravel log files in a simple UI

A simplistics log viewer for your Filament apps. This package provides a Logs page that allows you to view your Laravel log files in a simple UI. Inst

A package that adds view-composer like feature to Inertia.js Laravel adapter

Kinetic A package that adds view-composer like feature to Inertia.js Laravel adapter. Use to be able to share props based on the Inertia component nam

This package provides a Filament resource to view all Laravel sent emails.
This package provides a Filament resource to view all Laravel sent emails.

This package provides a Filament resource to view all Laravel outgoing emails. It also provides a Model for the database stored emails. Installation Y

GeoLocation-Package - This package helps you to know the current language of the user, the country from which he is browsing, the currency of his country, and also whether he is using it vpn
GeoLocation-Package - This package helps you to know the current language of the user, the country from which he is browsing, the currency of his country, and also whether he is using it vpn

GeoLocation in PHP (API) 😍 😍 😍 This package helps you to know a lot of information about the current user by his ip address 😍 😍 😍 This package h

Quickly identify controller methods with no route in your Laravel applications.
Quickly identify controller methods with no route in your Laravel applications.

Orphan Controller Quickly identify controller methods with no route in your Laravel applications. Installation You can install the package via Compose

Releases(1.0.1)
Owner
Touhidur Rahman
Husband, father, big time documentary tv series lover and software engineer . Passionate about PHP, Laravel, Ruby on Rails, Vue.js and C/C++ . Learning Rust .
Touhidur Rahman
A mostly useless package to display framework versions at the bottom of the Admin navigation panel.

A mostly useless package to display framework versions at the bottom of the Filament Admin navigation panel and an optional widget to do the same in the dashboard or custom pages.

Adam Weston 10 Nov 8, 2022
View themes is a simple package to provide themed view support to Laravel.

Laravel View Themes View themes is a simple package to provide themed view support to Laravel. Installation Add alexwhitman/view-themes to the require

Alex Whitman 15 Nov 29, 2022
Laravel Composable View Composers Package - Compose View Composers from Component Composers

Laravel Virtuoso Laravel Composable View Composers Package Increase flexibility and reduce code duplication by easily composing complex View Composers

Yitzchok Willroth 68 Dec 29, 2021
Jetstrap is a lightweight laravel 8 package that focuses on the VIEW side of Jetstream / Breeze package installed in your Laravel application

A Laravel 8 package to easily switch TailwindCSS resources generated by Laravel Jetstream and Breeze to Bootstrap 4.

null 686 Dec 28, 2022
an opensourced roblox group finder writen in python 100% free and virus-free

Roblox-Group-Finder an opensourced roblox group finder writen in python 100% free and virus-free note : if you don't want install python or just use w

mollomm1 1 Nov 11, 2021
Log requests and group together for aggregated statistics of route usage

Log Laravel route usage statistics Log Laravel requests and responses for statistical purposes and optionally aggregate by hours/days/months for minim

Bilfeldt 108 Dec 11, 2022
Add a general-purpose tools page to your Filament project. πŸ› 

Add a general-purpose tools page to your Filament project. Installation You can install the package via Composer: composer require ryangjchandler/fila

Ryan Chandler 24 Dec 6, 2022
A general-purpose parser for Laravel's Blade templating engine.

A general-purpose parser for Laravel's Blade templating engine. This is where your description should go. Try and limit it to a paragraph or two. Cons

Ryan Chandler 6 Feb 18, 2022
Adds a widget and REST endpoint for the purpose of displaying post revisions inline on the frontend.

Post History This widget allows visitors to easily diff posts against their earlier revisions, displaying diffs of HTML inline. It should be plug and

Human Made 4 Dec 12, 2022
A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic

A light weight laravel package that facilitates dealing with arabic concepts using a set of classes and methods to make laravel speaks arabic! concepts like , Hijri Dates & Arabic strings and so on ..

Adnane Kadri 49 Jun 22, 2022