Generate a flutter app from your Tomato App!
Tags: laravel, tomato, php, flutter
Published: 2023-10-12 18:16:47


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ys7vcysizytnwvt2w3a6.png)

as we go to make everything easy, we are today releasing a very very good package to build a flutter app by just using 1 command to generate full CRUD from your schema and generated TomatoPHP files

## Requirements
please check that you have flutter installed and working on your system by check

```bash
flutter doctor
```

and you must have at least one emulator or device connected to your system

and you must have 2 packages working on your Laravel app [Tomato Admin](https://dev.to/3x1io/tomatophp-admin-crud-generator-257k) and [Tomato CRM](https://docs.tomatophp.com/plugins/tomato-crm)

after installing the package please make sure that you add a guard of `accounts` to your auth.php config like this

```php
    'guards' => [
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'accounts' => [
            'driver' => 'session',
            'provider' => 'accounts',
        ],
    ],

...


    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],

        'accounts' => [
            'driver' => 'eloquent',
            'model' => \TomatoPHP\TomatoCrm\Models\Account::class,
        ],
    ],

```

## Installation

```bash
composer require tomatophp/tomato-flutter
```

now you are ready to generate a new app

to generate a new app you just need to run this command

```
php artisan tomato-flutter:generate
```

### Generate Module <a href="#user-content-generate-module" id="user-content-generate-module"></a>

to generate a new module you just need to run this command

```
php artisan tomato-flutter:module
```

### Generate Controller <a href="#user-content-generate-controller" id="user-content-generate-controller"></a>

to generate a new controller you just need to run this command

```
php artisan tomato-flutter:controller
```

### Generate Service <a href="#user-content-generate-service" id="user-content-generate-service"></a>

to generate a new service you just need to run this command

```
php artisan tomato-flutter:service
```

### Generate CRUD

to generate a new CRUD from any table on  your tomato-php generated CRUDs just need to run this command

```
php artisan tomato-flutter:crud
```

please note that the generated files will match only APIs generated by TomatoPHP and you need to add API routes to the api.php&#x20;

```php
Route::middleware(['auth:sanctum'])->name('api.')->group(function () {
    Route::get('customers', [\Modules\Customers\Http\Controllers\CustomerController::class, 'index'])->name('customers.index');
    Route::post('customers', [\Modules\Customers\Http\Controllers\CustomerController::class, 'store'])->name('customers.store');
    Route::get('customers/{model}', [\Modules\Customers\Http\Controllers\CustomerController::class, 'show'])->name('customers.show');
    Route::post('customers/{model}', [\Modules\Customers\Http\Controllers\CustomerController::class, 'update'])->name('customers.update');
    Route::delete('customers/{model}', [\Modules\Customers\Http\Controllers\CustomerController::class, 'destroy'])->name('customers.destroy');
});
```

### Change Endpoint

if you like to change the endpoint to match your URL you can change it from the file

```
flutter/YOUR_APP/lib/config/Config.dart
```

and change it to your endpoint, if you are using Android you check the app please make the endpoint hit to [`http://10.0.2.2:8000/api`](http://10.0.2.2:8000/api) and run&#x20;

```bash
php artisan serv
```

on your app.