laravel-transporter icon indicating copy to clipboard operation
laravel-transporter copied to clipboard

Suggestions for Improvements

Open VimKanzoGH opened this issue 1 year ago • 2 comments

Hello, @JustSteveKing thank you for this great package once again and also for the quick fixes from yesterday. I was thinking about some ways you could improve the package. Below is an example:

I'm working on an app that consumes solely on an API developed in Laravel, now for crud operations like Post management, I would have to create a Transport Request class for all the crud operations which is how the current package works (I stand to be corrected). I would have wished to just create one class e.g UpsertPosts or PostTransporter which will take care of all the crud operations instead of creating different classes for Create, Read, Update and Delete.

In the end, I would love to be able to do something like this:

<?php

namespace App\Http\Controllers;

$post = PostTransporter::build()
->method('Post') or ->post (making it possible to overwrite the method via this constructor
->send();

Also instead of adding ->withData(['title' => $request->title]), I would like to be able to pass the data instead inside the PostTransporter class to keep things clean maybe via the constructor like so:

<?php

declare(strict_types=1);

namespace App\Transporter\Requests\Sour\Posts;

use JustSteveKing\Transporter\Request;
use App\Http\Requests\UpsertPostRequest;

class Post extends Request
{
    protected string $method = 'GET';
    protected string $path = '/v1/post/{id}';


    public function __construct(UpsertPostRequest $request) {
        'title' => $request->id,
        'description' => $request->description,
        'release_date' => $request->release_date,
    }

    public function rules(): array
    {
        return [
            'title' => 'required',
            'description' => 'required',
            'release_date' => 'required',
            'rating' => 'required',
            'ticket_price' => 'required',
            'country' => 'required',
            'genre' => 'required',
            'photo' => 'required',
        ];
    }
}

NB: So one can define the validation rule via the function above or just import their validation request as I did in the construct

I hope I was able to explain myself well. This would have been super amazing to have. Once again thanks for all the hard work.

VimKanzoGH avatar Oct 05 '22 10:10 VimKanzoGH