Basic Laravel Helpers for requests and controllers build by TomatoPHP
tomatophp/laravel-tomato is a Laravel package for basic laravel helpers for requests and controllers build by tomatophp.
It currently has 1 GitHub stars and 4 downloads on Packagist (latest version v1.0.0).
Install it with composer require tomatophp/laravel-tomato.
Discover more Laravel packages by tomatophp
or browse all Laravel packages to compare alternatives.
Last updated

Basic Laravel Helpers for requests and controllers build by TomatoPHP
composer require tomatophp/laravel-tomato
Tomato::menu() inject and handle menus across your applicationTomato::widget() inject and handle widgets across your applicationTomato::slot() inject and handle slots across your applicationTomato::request() handle and validate requestsTomato::response() handle api responsesyou can use the helper by Facade class or by using the helper function
use TomatoPHP\LaravelTomato\Facades\Tomato::register();
or just
tomato()::register();
you can register your menu, widget, or slot in your service provider boot() method
Tomato::register([
Menu::make()
->group(__('CRM'))
->label(__('Name'))
->route('home')
->icon('home'),
Widget::make()
->group(__('CRM'))
->label(__('Name'))
->counter(100)
->icon("bx bx-user"),
Slot::make()
->position(Positions::dashboardTop)
->view('dashboard-top'),
]);
you can register any type of component and we will check it and handle it for you
all components have a macroable methods to add more functionality to it.
you can get your components like this
Tomato::menu()->get();
Tomato::widget()->get();
Tomato::slot()->get();
it will return an array of registered components for you
you can use the request helper to handle and validate your requests like this
return Tomato::request()->index(
request: request(),
model: App\Models\User::class,
);
this method returns view or JsonResponse based on the request type. and we get the request type by check if the route has auth:sanctum middleware or not.
this method accept some arguments:
request the request objectmodel the model you want to getview the view you want to returntable the table class you want to usedata the data you want to pass to the viewapi if you want to return JsonResponse or notresource resource class to resource your returned dataquery if you want to add some query to the modelfilters if you want to add some filters to the tablepublic function index(Request $request): View|JsonResponse
{
return Tomato::index(
request: $request, //Required
model: $this->model, //Required
view: 'users.index',
table: \App\Tables\UserTable::class,
data: [
'name' => 'john doe',
],
api: true,
resource: UserResource::class,
query: User::query()->where('is_activated',true),
filters: [
'is_activated',
],
);
}
this method return only json response of the model to make it easy to access it with x-splade-select or x-tomato-admin-select
this method accept some arguments:
request the request objectmodel the model you want to getdata the data you want to pass to the viewpaginate if you want to paginate the response or notquery if you want to add some query to the modelfilters if you want to add some filters to the tablepublic function api(Request $request): JsonResponse
{
return Tomato::json(
request: $request, //Required
model: \App\Models\User::class, //Required
data: [
'name' => 'john doe',
],
paginate: 10,
query: User::query()->where('is_activated',true),
filters: [
'is_activated',
],
);
}
this method returns view or JsonResponse based on the request type. and we get the request type by check if the route has auth:sanctum middleware or not.
this method accept some arguments:
model the model you want to getview the view you want to returndata the data you want to pass to the viewhasMedia if you want to get the media of the model or notcollection [array] the media collection you want to get as array take true if it's multi or false if it's singleattach [array] to attach some data to the modelapi if you want to return JsonResponse or notresource resource class to resource your returned dataquery if you want to add some query to the modelpublic function show(\App\Models\User $model): View|JsonResponse
{
return Tomato::get(
model: $model, //Required
view: 'users.show', //Required
data: [
'name' => 'john doe',
],
hasMedia: true,
collection: [
'avatar' => false,
'gallery' => true
],
attach: [
'roles' => $model->roles,
],
api: true,
resource: UserResource::class,
query: User::query()->where('is_activated',true)
);
}
this method returns RedirectResponse or JsonResponse based on the request type. and we get the request type by check if the route has auth:sanctum middleware or not.
this method accept some arguments:
request the request objectmodel the model you want to getvalidation the validation rules you want to usemessage the message you want to return with the responsevalidationError the message you want to return if the validation failedredirect the redirect route you want to redirect tohasMedia if you want to get the media of the model or notcollection [array] the media collection you want to get as array take true if it's multi or false if it's singleapi if you want to return JsonResponse or notpublic function store(Request $request): RedirectResponse|JsonResponse
{
$response = Tomato::store(
request: $request, //Required
model: \App\Models\User::class, //Required
validation: [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
],
message: __('User created successfully'),
validationError: __('Error When Try To Store User'),
redirect: 'admin.users.index',
hasMedia: true,
collection: [
'avatar' => false,
'gallery' => true
],
api: true,
);
if($response instanceof JsonResponse){
return $response;
}
return $response->redirect;
}
this method returns RedirectResponse or JsonResponse based on the request type. and we get the request type by check if the route has auth:sanctum middleware or not.
this method accept some arguments:
request the request objectmodel the model you want to getvalidation the validation rules you want to usemessage the message you want to return with the responsevalidationError the message you want to return if the validation failedredirect the redirect route you want to redirect tohasMedia if you want to get the media of the model or notcollection [array] the media collection you want to get as array take true if it's multi or false if it's singleapi if you want to return JsonResponse or notpublic function update(Request $request, \App\Models\User $model): RedirectResponse|JsonResponse
{
$response = Tomato::update(
request: $request, //Required
model: $model, //Required
validation: [
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
],
message: __('User updated successfully'),
redirect: 'admin.users.index',
hasMedia: true,
collection: [
'avatar' => false,
'gallery' => true
],
api: true,
);
if($response instanceof JsonResponse){
return $response;
}
return $response->redirect;
}
this method returns RedirectResponse or JsonResponse based on the request type. and we get the request type by check if the route has auth:sanctum middleware or not.
this method accept some arguments:
model the model you want to getmessage the message you want to return with the responseredirect the redirect route you want to redirect toapi if you want to return JsonResponse or notpublic function destroy(\App\Models\User $model): RedirectResponse|JsonResponse
{
$response = Tomato::destroy(
model: $model, //Required
message: __('User deleted successfully'), //Required
redirect: 'admin.users.index',
);
if($response instanceof JsonResponse){
return $response;
}
return $response->redirect;
}
to make media handling work you must install spatie/laravel-medialibrary package and run the migration
composer require spatie/laravel-medialibrary
php artisan vendor:publish --provider="Spatie\MediaLibrary\MediaLibraryServiceProvider" --tag="migrations"
php artisan migrate
and your model must use HasMedia trait
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
class User extends Model implements HasMedia
{
use InteractsWithMedia;
}
and we have handel Toaster for you if you are using Splade it will working automatically and if you have yoeunes/toastr package it will working fine too. or you can use fetch toaster variable from session to get the flash messages.
you can join our discord server to get support TomatoPHP
Please see CHANGELOG for more information on what has changed recently.
Please see SECURITY for more information about security.
The MIT License (MIT). Please see License File for more information.